1

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?

davbryn
  • 7,156
  • 2
  • 24
  • 47

2 Answers2

3

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.

heemin
  • 321
  • 3
  • 12
2

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

Michael Kessler
  • 14,245
  • 13
  • 50
  • 64
  • 4
    Unfortunately, that means you can't take advantage of different appearance when the button is disabled. – Rick Jan 14 '16 at 02:33