iPhone - 单击手势与双击手势冲突

发布于 2024-11-30 22:39:56 字数 493 浏览 1 评论 0原文

我有一个看法。我希望为其定义各种点击手势。

因此,如果用户单击视图,视图将执行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太傻旳人生 2024-12-07 22:39:56

您可以通过添加以下代码行来解决此问题。这将确保单击识别器仅在双击识别器失败时触发:

    [singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文