0

我如何使用 iOS 和 Sprite Kit 检测手指触摸屏幕的时间。我想得到从手指第一次触摸到释放它的时间,但我不知道如何。

4

1 回答 1

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);
}
于 2013-10-05T14:34:50.923 回答