iphone - single tap gesture conflicts with double one

ぐ巨炮叔叔 提交于 2019-12-08 23:08:27

问题


I have a view. I wish to define to kinds of tap gestures for it.

So if a user single tap on the view, view will do A; and if a user double tap on the view, it will do B without doing A.

I added two UITapGestureRecognizer to the view. the single tap is with numberOfTapsRequired = 1; and the double tap is with numberOfTapsRequired = 2;

Also I set return NO for

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
     return NO;
}

However, I found that they conflict with each other. I mean, even if I double tap on the view, both A and B will be invoked.

How can I solve this problem?

Thanks


回答1:


You can work around this by adding the following line of code. This will make sure that the single tap recognizer only fires when the double tap recognizer failed:

    [singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer];


来源:https://stackoverflow.com/questions/7175086/iphone-single-tap-gesture-conflicts-with-double-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!