2009-08-20 9 views

答えて

19
// add this ivar to your view controller 
NSTimeInterval lastTouch; 

// assign the time interval in touchesBegan: 
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 
{ 
    lastTouch = [event timestamp]; 
} 


// calculate and print interval in touchesEnded: 
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 
{ 
    NSTimeInterval touchBeginEndInterval = [event timestamp] - lastTouch; 

    NSLog(@"touchBeginEndInterval %f", touchBeginEndInterval); 
} 
0

touchesBegan:withEvent:メソッドでは、NSDateオブジェクトを作成し、それをインスタンス変数に格納します。 (デバッグ目的でない場合は、1回のタッチで日付を作成し、CFMutableDictionaryを使用して日付をタッチに関連付けます)。touchesEnded:withEvent:では、保存された日付を取得して新しい日付を作成し、後者にtimeIntervalSinceDate:メッセージを送信してそれからの日付、あなたに秒単位で結果を与える。

+0

それは私の理解のcocos2dだが、これらのメソッドを実装するの世話をし、それらを離れて抽象化します。 – jbrennan

+0

@jbrennan、どうですか?あなたはそれについて詳述できますか? –

2

各UITouchには、独自の時刻/日付スタンプがあります。あなたが興味を持っているものを比較してください。UIResponderクラスのrefを参照してください。

Aside-SOはコードを更新したり、iPhoneアプリをリリースする必要があります。 iPhoneでjavascriptoidedテキストフィールドに入力するのは、ほとんどコミックです。

関連する問題