pajevic
pajevic

Reputation: 4667

Hidden UIButton still receives touch events. The tap recognizer below does not

I have an UIView which has an UITapGestureRecognizer attached to it. I also have an UIButton which is a sibling to the mentioned view (i.e. they are placed in the same superview). The button is placed above the view.

The button is sometimes hidden. In this situation I want the taps to go through to the tap gesture recognizer in the view below. However, even though the hidden property of the button is set to true it still receives the Touch Up Inside event. It is my understanding that this should not happen since the documentation for the hidden property of UIView (where the UIButton gets the property from) states A hidden view disappears from its window and does not receive input events.

I have tried setting both enabled and userInteractionEnabled properties of the button to false. In both cases the button no longer receives the Touch Up Inside event, but the tap recognizer below it doesn't receive the tap event either.

Is there a way to achieve what I need in my current view hierarchy?

Upvotes: 0

Views: 426

Answers (1)

Abhishek B
Abhishek B

Reputation: 187

Instead of hiding button disable button . button.isEnabled = false . So it will not receive events .

Upvotes: 0

Related Questions