开发者

Deselect UIButton on touch down outside

开发者 https://www.devze.com 2022-12-19 07:36 出处:网络
I have a UIButton that selects itself on 开发者_如何学PythonUIControlEventTouchUpInside.It deselects itself on UIControlEventTouchUpOutside.I also want it to deselect itself when there is a touch down

I have a UIButton that selects itself on 开发者_如何学PythonUIControlEventTouchUpInside. It deselects itself on UIControlEventTouchUpOutside. I also want it to deselect itself when there is a touch down outside of the button. Is there a good way to do this without subclassing UIWindow and overriding -hitTest:withEvent:?

EDIT: I just found this question, which confirms my fear that there isn't a really clean way to do this.


This is not how buttons are supposed to work. They cannot be active if there is no touch active inside them. What are you really trying to implement? Maybe a UIBUtton is not the best choice here.


You can do this with your UIViewController by implementing the touchesBegan/Moved/Ended methods. If they detect a touch outside of the button, set its state back to normal. Take a look at Event Handling.


I solved this, and released the source. I didn't have to subclass UIWindow, but I did need to override -hitTest:withEvent:.

0

精彩评论

暂无评论...
验证码 换一张
取 消