Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About messages from UITapGestureRecognizer

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

like image 479
Stanley Avatar asked Sep 27 '11 09:09

Stanley


Video Answer


2 Answers

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

like image 111
Ashley Mills Avatar answered Sep 16 '22 19:09

Ashley Mills


- (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

}
like image 23
Aman Gupta Avatar answered Sep 16 '22 19:09

Aman Gupta