質問

How can we get the time a user spent to finish a swipe right or swipe left action? Already googled but no luck. If there is not built-in solution already, will touch begin and touch end together work?

役に立ちましたか?

解決

Measure the start and end time, and calculate the difference in the UIGestureRecognizer callback method for gestureRecognizer.state == UIGestureRecognizerStateBegan and gestureRecognizer.state == UIGestureRecognizerStateEnded

他のヒント

You can do this by getting the date (which you create as ivar or property) in the touchesBegan method like this:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
   touchStartDate = [NSDate date];

}

Then you fetch the difference in the touches end method:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
     NSTimeInterval *touchDuration = [[NSDate date] timeIntervalSinceDate:touchStartDate];
     NSLog(@"Touchduration %f",touchDuration);
}

If you only want to get the duration of a swipe left/right gesture you also need to check if the x value of the touch changed. This should be easy.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top