取消触摸UIButton触摸移动(iOS) [英] Cancel touch on UIButton on touch move (iOS)

查看:254
本文介绍了取消触摸UIButton触摸移动(iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮和触摸移动手势的视图。当用户触摸按钮时,它被选中并且继续接收触摸移动事件。我想在触摸移动上取消选择按钮,并将动作移动到手势。



如何在优雅按钮上取消触摸接收?

解决方案

您需要实现UIGestureRecognizerDelegate。具体这个方法。然后只需建立你的逻辑来决定手势是否应该接受触摸。如果你返回NO,那么触摸就是为了抓住按钮。 (UIGestureRecognizer *)手势识别器shouldReceiveTouch :( UITouch *)触摸

如果你没有更多的控制,我认为你需要对按钮进行子类化和接管它的命中测试。


I have a view with button and touch-move gesture. When user touches button it becomes selected and keeps receiving touch-move events. I want to deselect the button on touch-move and pass moves to gesture.

How to cancel touch receiving on button "elegantly"?

解决方案

You need to implement the UIGestureRecognizerDelegate. Specifically this method. Then just build your logic for deciding if the gesture should receive the touch or not. If you return NO then the touch is up for grabs for the button. if you return YES the gesture to take the touch.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

If you never even more control I think you'll need to subclass the button and takeover its hit testing.

这篇关于取消触摸UIButton触摸移动(iOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆