开发者

Custom UIButton + subviews = no events

开发者 https://www.devze.com 2022-12-28 15:10 出处:网络
Basically I have a custom UIButton and this custom button con开发者_运维知识库tains subviews. If I add those subviews to my UIButton, then the button stops responding to event changes. I.e if I tap on

Basically I have a custom UIButton and this custom button con开发者_运维知识库tains subviews. If I add those subviews to my UIButton, then the button stops responding to event changes. I.e if I tap on it it doesn't respond to the selector. I have everything set as userInteractionEnabled. I also tried adding touchbegan and this is working. If I remove those subviews, the UIButton works again.

How Do I get the tap events from the button?


The subviews should have userInteractionEnabled set to NO. What is happening here is that the subviews are getting the touch events instead of the UIButton. If that doesn't work another option is to override hitTest:withEvent: in your custom UIButton so that it always returns itself and does not ask its subviews if they should handle the event. See the UIView docs for more details.

0

精彩评论

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

关注公众号