How exactly do I detect how long a finger has been touching the screen with iOS and Sprite Kit. I would like to get the amount of time from the first touch of the finger to the release of it, but I don't know how.
Add this code to your 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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.