8
votes

The following is from documentation :

Although taps are discrete gestures, they are discrete for each state of the gesture recognizer; thus the associated action message is sent when the gesture begins and is sent for each intermediate state until (and including) the ending state of the gesture.

The above passage seems to indicate that more than one message is sent. The messages would include a "begin" message and an "end" message. But somehow I just get the "gesture end" message. Is there any way I can get both the tap begin and end message ? (What I wish to track is - "begin" : the moment the user touches the screen and "end" : the moment the user lifts his finger away from the screen.)

Hope that somebody who is knowledgable on this could help ...

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITapGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UITapGestureRecognizer

3
I was also confused by the documentation, which goes on to say Code that handles tap gestures should therefore test for the state of the gesture and lists code to test for the UIGestureRecognizerStateEnded state. All this seeming to indicate that the tap gesture recognizer would send more than just the ended event.cod3monk3y
Yep, but that stands in stark contrast to the simple truth that we see only the one event and that the Handling UIKit Gestures even tells us that our handler will be called “exactly once” for discrete gestures. I suspect that there’s some edge case that can cause multiple events to be triggered (otherwise all those caveats they added to the UITapGestureRecognizer documentation don’t make sense), but it’s not clear how...Rob

3 Answers

15
votes

The UITapGestureRecognizer only fires when the gesture state is UIGestureRecognizerStateEnded

If you want to use a gesture recogniser to detect the start and end of a press, use the UILongPressGestureRecognizer, with the minumumPressDuration set to 0

4
votes
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

      NSDate *date1 = [NSDate date]; //user touches the screen


}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

      NSDate *date2 = [NSDate date];  //user lifts his finger away from the screen

}
1
votes

Why don't you use - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event method ?