2009-08-20 97 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对象并将其存储在一个实例变量中。 (对于非调试目的,请为每次触摸创建一个日期,并使用CFMutableDictionary将日期与触摸关联。)然后,在touchesEnded:withEvent:中,检索存储的日期并创建一个新日期,并发送后者一个timeIntervalSinceDate:消息以减去较旧从它的日期,在几秒钟内给你结果。

+0

这是我的理解cocos2d负责实施这些方法并将它们抽象出来。 – jbrennan 2009-08-20 18:00:49

+0

@jbrennan,怎么样?你能详细说明一下吗? – 2016-04-24 04:51:56

2

每个UITouch都有自己的时间/日期标记。比较你感兴趣的人。在UIResponder类别参考。

Aside- SO需要更新他们的代码或发布iPhone应用程序。用iPhone输入他们的javascriptoided文本字段几乎是滑稽的。