我究竟如何通过iOS和Sprite Kit检测手指触摸屏幕的时间长度。我想从手指的第一次触摸到释放它的时间,但我不知道如何。
答案 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);
}