简体   繁体   中英

UIButton passes touches to superview when disabled - how can I avoid this?

I have a UIButton that I disable for a few seconds after the user clicks it (using button.enabled = NO ). The button disables, but touching it whilst disabled causes the view behind to receive the touch - something I don't want.

I've tried button.userInteractionEnabled = NO as well but this has the same problem.

Can I have the button consume the touch? Or do I have to keep it enabled and programatically halt code execution in the IBAction ?

What I did is placing UIImageView of same size with UIButton just under the UIButton. Then even though you disable UIButton, touch events do not propagate UIImageView.

Don't disable it - just don't execute the method that is called on tap.
You might keep some boolean that will keep button's "virtual" state (active or not) and according to this boolean execute or don't execute the action...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM