iPhone - 单击手势与双击手势冲突
我有一个看法。我希望为其定义各种点击手势。
因此,如果用户单击视图,视图将执行 A;如果用户双击视图,它将执行 B,而不执行 A。
我向视图添加了两个 UITapGestureRecognizer。单击时 numberOfTapsRequired = 1;双击时 numberOfTapsRequired = 2;
我还设置了 return NO
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return NO;
}
但是,我发现它们相互冲突。我的意思是,即使我双击视图,A 和 B 都会被调用。
我该如何解决这个问题?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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: