您可以禁用 UIButton 而不禁用其附加的 UIGestureRecognizers 吗?
我有一个具有 2 个功能的 UIButton:点击和长按。有点像 Springboard 应用程序(主屏幕)。我已将其实现为附加有 UILongPressGestureRecognizer 的 UIButton。
在某些情况下,我需要通过在按钮上设置 enabled = NO
来禁用点击操作。但不幸的是,这也禁用了我的手势识别器。
如何禁用 UIButton 的标准行为,同时保持附加的手势识别器处于活动状态?
I have a UIButton with 2 functions: tap, and long press. A bit like the Springboard app (home screen). I've implemented it as a UIButton with a UILongPressGestureRecognizer attached.
In some cases I need to disable the tap action which i do by setting enabled = NO
on my button. But unfortunately this also disabled my gesture recogniser.
How do I disable the UIButton's standard behaviour while keeping the gesture recogniser attached to it active?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIButton 是 UIControl 的子类。
看看UIControl中的各种方法。
您可以指定调用 ControlEvents(例如 ControlEventTouchUpInside 又名 tap)和 UIEvents 的特定方法。
您可以使用以下方法删除控制事件的操作:
或者,根据您的条件,您可以在调用的目标/选择器方法中仅执行无操作。
UIButton is a sub-class of UIControl.
Look at the various methods in UIControl.
You can specify specific methods to call for ControlEvents (such as ControlEventTouchUpInside a.k.a tap) and for UIEvents.
You can remove actions for control events with:
Or, depending on your conditions, you can just no-op inside the target/selector method that is called.
您可以删除按钮的点击目标和选择器,然后在需要时再次添加。通过设置
enabled = NO;
,您将UIControl的接收器设置为NO。更多文档
UIButton - 已启用
You could remve the button's tap target and selector and then add it again when you need it. By setting
enabled = NO;
you are setting the UIControl's receivers to NO.More Docs
UIButton - Enabled