[英]Stop the UIButton being 'active' when finger is dragged outside its bounds
How can I make the area of a UIButton
in which the button still triggers the touchUpInside
method smaller? 如何使按钮仍然触发
touchUpInside
方法的UIButton
区域更小? When I press a button and drag my finger outside it (not lifting the finger), the area outside the button's bounds that keeps the button highlighted is pretty large. 当我按下一个按钮并将我的手指拖到它外面时(不抬起手指),按钮突出部分之外的区域使按钮突出显示非常大。
I would like to achieve that the touchUpInside
method would only get triggered if the finger (being dragged) is still inside the bounds of the button. 我想实现只有当手指(被拖动)仍然在按钮的边界内时才会触发
touchUpInside
方法。 Currently, if you press a button and, while not lifting your finger, you drag your finger outside the button, the area in which the touchUpInside
method (instead of the touchUpOutside
method) is called is pretty big. 目前,如果您按下一个按钮,并且在不抬起手指的同时将手指拖到按钮外部,则
touchUpInside
方法(而不是touchUpOutside
方法)的区域非常大。 Can I limit the touchUpInside
method to get called only if the finger is inside the bounds of the button? 我是否可以限制
touchUpInside
方法仅在手指位于按钮边界内时才被调用?
Thank you. 谢谢。
I'm not pretty sure if I clearly understand your problem. 我不确定我是否清楚地了解你的问题。 So I would like to provide my 2 solutions:
所以我想提供我的2个解决方案:
The tricky one: you add another smaller subview to the button which being dragged, you turn off userInteraction of this button and reactivate it when you're done dragging. 棘手的一个:你在拖动的按钮上添加另一个较小的子视图,关闭此按钮的userInteraction并在完成拖动后重新激活它。
Disable userInteraction for the stable button, you recognise if the two buttons touch each others base on their frame. 禁用稳定按钮的userInteraction,您可以识别两个按钮是否基于其框架相互接触。 Reactive userInteraction when you're done just like above.
如上所述完成后的反应性userInteraction。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.