Reputation: 3775
I am wondering how I would go about measuring the time in between touches inside a view in the iPhone SDK. I know that the first event triggered is touchesBegan: and then the last one triggered is touchesEnded:, however I just don't know how I would go about measuring the time that the user has touched the view for. For instance, if they keep their finder in the view for 2 seconds, it will automatically trigger function twoSeconds: or something like that.
Thanks for any help!
Upvotes: 0
Views: 873
Reputation: 36762
Use [NSDate date]
to get the current date and time. Store it in touchesBegan:
, and fetch the duration in touchesEnded:
as this
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:beganDate];
You will now have the duration between the events measured in seconds in length
.
Upvotes: 3