1

Is it possible to be able to click a button and let the tap trickle down to the parent View of a button? I have tried disabling the button and the tap gets detected, but is it possible to click on the button, do something and then let the tap event trickle down?

UIViewControllerWrapperView contains UIView contains UIView contains UIButton

When I click/press the button should go like so,

Click button > UIView tapped > UIView tapped > UIViewControllerWrapperView detect tap

Edit: I can detect Taps on UIViewControllerWrapperView, however, if I click on the button, the Taps are not detected because I'm assuming the click event gets handled by the button which in turn blocks the tap from being detected by the views underneath.

Marin
  • 12,531
  • 17
  • 56
  • 80
  • Your question is not quite clear. Do you want to detect touch in UIViewControllerWrapperView ? – Sandeep Dec 18 '16 at 23:09
  • Hi Sandeep, I edited my question for better clarification - thank you. – Marin Dec 18 '16 at 23:12
  • Would [this post](http://stackoverflow.com/a/32942445/2092663) help? You might need to override other events such as touchesEnded and touchesCancelled. – Mobile Dan Dec 19 '16 at 18:18

1 Answers1

1

isUserInteractionEnabled property

Try setting the UIButton's isUserInteractionEnabled property to false. The default is true for a UIButton.

Note that isUserInteractionEnabled is declared on the UIView class which UIButton inherits from.

 

Set isUserInteractionEnabled in Code

button.isUserInteractionEnabled = false

 

Set isUserInteractionEnabled in Interface Builder

In attributes inspector for the UIButton:

enter image description here

Mobile Dan
  • 6,444
  • 1
  • 44
  • 44
  • Hello Dan thank you for your reply, I realize that isUserInteractionEnabled will let the tap through, but it won't recognize the tap itself either, I don't want the tap to be exclusive but rather inclusive , available to both the button and underlying view? Thanks – Marin Dec 19 '16 at 01:43
  • Hi @Marin, I should've known it wouldn't be that easy! I will leave my answer here so others can rule it out and in case it helps arrive at the solution. – Mobile Dan Dec 19 '16 at 18:05
  • Hello Dan, I ended up overriding UIApplication and combined with your input , I turned off User Interaction Enabled, was able to make my case work, albeit more of a hack. Thanks! – Marin Dec 19 '16 at 19:22