About messages from UITapGestureRecognizer

2020-04-04 14:28发布

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条回答
▲ chillily
2楼-- · 2020-04-04 15:10

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

查看更多
爷、活的狠高调
3楼-- · 2020-04-04 15:19
- (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

}
查看更多
Bombasti
4楼-- · 2020-04-04 15:19

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

查看更多
登录 后发表回答