The time between touch and touch has begun

Is there any method in objective-c to find the time between touch and touch is over?

+3
source share
3 answers
// add this ivar to your view controller
NSTimeInterval lastTouch;

 // assign the time interval in touchesBegan:
 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
 {
     lastTouch = [event timestamp];
 }  


 // calculate and print interval in touchesEnded:
 -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
{
    NSTimeInterval touchBeginEndInterval = [event timestamp] - lastTouch;

    NSLog(@"touchBeginEndInterval %f", touchBeginEndInterval);
}   
+19
source

Each UITouch has its own time / date stamp. Compare those that interest you. Take a look at the UIResponder ref class.

Aside-SO needs to update its code or release an iPhone app. Typing in their javascriptoided text fields from the iPhone is almost ridiculous.

+2
source

In your method, touchesBegan:withEvent:create an NSDate object and save it in an instance variable. (For purposes without debugging, create one date with one touch and use CFMutableDictionary to bind the date with a touch.) Then touchesEnded:withEvent:find the saved date and create a new date and send the last message to timeIntervalSinceDate:subtract the older date from it, giving the result in seconds.

0
source

Source: https://habr.com/ru/post/1715618/


All Articles