自定义UIControl在滚动时获取touchesCancelled;如何禁用滚动?
我正在编写一个 UISwitch 替代品(带有自定义图形)。我已经覆盖了 TouchMoved 和朋友,以便您可以在“是”和“否”之间拖动小部件,就像使用 UISwitch 一样。
如果将其放置在滚动视图中,如果用户对角移动手指而不是完全水平移动手指,触摸将被取消,并且滚动会开始。我注意到 UISwitch 和 UIButton 没有表现出这种行为,并且在操作这些控件时滚动永远不会启动。
我如何告诉 UIKit 我想要对这些触摸进行独占控制,实际上是在 TouchBegan 中禁用滚动并在 End/Cancelled 中启用滚动?我确信有一些明显的事情,但我浏览了 UIControl、UIResponder、UIView 和 UIScrollView 的标题和文档,但没有找到任何内容。
注意:我不想创建 UIScrollView 子类;我无法想象作为正确的解决方案,控件应该是完全独立的。
I'm writing a UISwitch replacement (with custom graphics). I've overridden touchesMoved and friends, so that you can drag the widget between Yes and No, just as with UISwitch.
If you place it in a scroll view, touches will be cancelled if the user moves her finger the tiniest bit diagonally instead of perfectly horizontally, and scrolling kicks in instead. I've noted that UISwitch and UIButton do not exhibit this behavior, and scrolling never kicks in while manipulating these controls.
How can I tell UIKit that I want exclusive control over these touches, in effect disabling scroll in touchesBegan and enabling scroll in ended/cancelled? I'm sure there's something obvious, but I've looked through the headers and documentation for UIControl, UIResponder, UIView and UIScrollView and haven't found anything.
Note: I don't want to make a UIScrollView subclass; I can't imagine that being the right solution, the control should be completely standalone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在滚动视图中设置
canCancelContentTouches = NO
和在自定义控件中设置exclusiveTouch = YES
允许此行为(假设您愿意更改滚动视图上的属性)。Setting
canCancelContentTouches = NO
in the scroll view, andexclusiveTouch = YES
in a custom control allows this behaviour, assuming you are happy changing properties on the scroll view.