iphone - 单击手势与双击手势冲突 [英] iphone - single tap gesture conflicts with double one
问题描述
我有一个观点。我希望为它定义各种轻击手势。
I have a view. I wish to define to kinds of tap gestures for it.
因此,如果用户单击视图,视图将执行A;如果用户双击视图,它将执行B而不进行A。
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.
我在视图中添加了两个UITapGestureRecognizer。单击具有numberOfTapsRequired = 1;并且双击使用numberOfTapsRequired = 2;
I added two UITapGestureRecognizer to the view. the single tap is with numberOfTapsRequired = 1; and the double tap is with numberOfTapsRequired = 2;
此外,我为
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return NO;
}
但是,我发现它们相互冲突。我的意思是,即使我双击视图,也会调用A和B.
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.
如何解决这个问题?
谢谢
推荐答案
您可以通过添加以下代码行来解决此问题。这将确保单击识别器仅在双击识别器失败时触发:
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];
这篇关于iphone - 单击手势与双击手势冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!