有多个视图时如何禁用多点触控?
我创建了自己的自定义视图来扩展 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
exclusiveTouch
设置为YES
,而不是NO
(无论如何,这是默认值)。属性的名称指的是在持续时间内作为任何触摸事件的唯一接收者的视图。You need to set
exclusiveTouch
toYES
, notNO
(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.