有多个视图时如何禁用多点触控?

发布于 2024-10-09 01:09:38 字数 469 浏览 4 评论 0原文

我创建了自己的自定义视图来扩展 UIControl。这个自定义视图有自己的触摸实现。我在其中实现了touchesBegan、Moved、Ended 和Canceled 方法。

在主视图控制器中,我创建了该视图的多个实例。所以在屏幕上,有很多自定义按钮。

我想在我的应用程序中禁用多点触控。如果我单击一个自定义按钮,则其他按钮不应响应。

事实上,实现这个很容易。当我按住一些按钮时,我可以将其他按钮的 userInteractionEnabled 属性设置为 NO,直到我结束触摸。

但问题是,当我同时点击这几个按钮时,两个或多个touchesBegan方法同时工作,消息传递变得混乱。

我尝试设置multiTouchEnabled = NO和exclusiveTouch = YES,但还是没用。

如何在我的应用中强制禁用多点触控?

谢谢。

I created my own custom view that extends UIControl. This custom view has its own touch implementation. I implemented touchesBegan, Moved, Ended, and Canceled methods in it.

In the main view controller, I created several instances of this view. So in the screen, there are a number of custom buttons.

I want to disable multitouch in my app. If I click one custom button, then other buttons shouldn't respond.

Actually, it was easy to implement this. While I held some buttons, I could just make other buttons' userInteractionEnabled property to NO until I ended touch.

But the problem is that when I tap these several buttons at the same time, two or more touchesBegan methods work simultaneously, and message passing is messed up.

I tried to set multiTouchEnabled = NO and exclusiveTouch = YES, but it still didn't work.

How can I force to disable multitouch in my app?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

狂之美人 2024-10-16 01:09:38

您需要将 exclusiveTouch 设置为 YES,而不是 NO(无论如何,这是默认值)。属性的名称指的是在持续时间内作为任何触摸事件的唯一接收者的视图。

You need to set exclusiveTouch to YES, not NO (which is the default anyways). The name of the property refers to the view being the exclusive recipient of any touch events for the duration.

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