0

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?

pajevic
  • 4,607
  • 4
  • 39
  • 73
  • Please add code. – Code Farmer Oct 17 '19 at 09:23
  • Virtually everything I described is set up in Interface Builder, except `button.hidden = YES;` and `button.enabled = NO;` / `button.userInteractionEnabled = NO;`. – pajevic Oct 17 '19 at 09:25
  • @Nick As I explained in my comment above, there really isn't much code related to this issue. Everything is more or les done in Interface Builder. But if you need anything specific let me know. – pajevic Oct 17 '19 at 09:44
  • You could override the point function, as it's shown in this answer: https://stackoverflow.com/questions/3834301/ios-forward-all-touches-through-a-view – iSpain17 Oct 17 '19 at 10:16

1 Answers1

0

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

Abhishek B
  • 157
  • 8
  • As stated in the question I have already tried doing that, with different, but still unsatisfying results. – pajevic Oct 17 '19 at 11:24
  • Have you tried removing button from super view and adding to super view when you want it ? view.bringSubview(toFront: theButton) removeFromSuperview – Abhishek B Oct 17 '19 at 11:32