Reputation: 7840
Is there any method in objective-c to find the time between touch began and touch ended??
Upvotes: 3
Views: 3964
Reputation: 39691
// 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);
}
Upvotes: 18
Reputation: 38359
Each UITouch has it's own time/date stamp. Compare the ones you're interested in. Take a looke at the UIResponder class ref.
Aside- SO needs to update their code or release an iPhone app. Typing into their javascriptoided out text fields with an iPhone is almost comical.
Upvotes: 2
Reputation: 96373
In your touchesBegan:withEvent:
method, create an NSDate object and store it in an instance variable. (For non-debugging purposes, create one date per touch and use CFMutableDictionary to associate the date with the touch.) Then, in touchesEnded:withEvent:
, retrieve the stored date and create a new date, and send the latter a timeIntervalSinceDate:
message to subtract the older date from it, giving you the result in seconds.
Upvotes: 0