如何检测手指触摸屏幕iOS的时间长度

时间:2013-10-05 14:29:13

标签: ios objective-c sprite-kit

我究竟如何通过iOS和Sprite Kit检测手指触摸屏幕的时间长度。我想从手指的第一次触摸到释放它的时间,但我不知道如何。

1 个答案:

答案 0 :(得分:3)

将此代码添加到您的UIView:

NSDate *startTime; 

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    startTime = [NSDate date];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    NSTimeInterval elapsedTime = [startTime timeIntervalSinceNow];  
    NSLog(@"Elapsed time: %f", -elapsedTime);
}
相关问题