简体   繁体   English

当手指被拖出其边界时,停止UIButton处于“活动状态”

[英]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个解决方案:

  1. 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并在完成拖动后重新激活它。

  2. 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.

相关问题 触发将UIButton触摸内部的动作拖到外部,然后松开手指 - Trigger an action on UIButton touch inside dragged outside and then release finger 手指触摸/拖动时更改UIButton的大小 - Change UIButton size while finger is touching it/while it's being dragged UIButton将手指拖入边界 - UIButton drag finger into the bounds 当手指从1个按钮拖动到下一个按钮时如何触发UIButton事件 - How to trigger UIButton event when finger is dragged from 1 button to the next 点击后释放按钮,然后将其拖到边界之外 - Release a button after being tapped then dragged outside it's bounds 在按钮外开始触摸并在拖入按钮边界时触发事件 - Start touch outside a button and trigger an event when dragged into the bounds of button UIButton在设置为UITextField的leftView时接收界外的触摸事件 - UIButton receiving touch events outside bounds when set as leftView of UITextField UIButton UIControlEventTouchUpInside触发事件,即使在按钮框架之外拾取手指也是如此 - UIButton UIControlEventTouchUpInside triggering event even when picking up finger outside of button frame Swift:UIPanGestureRecognizer如何判断是否在屏幕外使用了拖曳的手指 - Swift: UIPanGestureRecognizer How to tell if use dragged finger outside screen 命中测试位于SuperView范围之外的UIButton - Hit Testing a UIButton located outside bounds of SuperView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM