Search code examples
uiimageviewuibuttontouches

iOS. How Do Enable a Transparent Image to Pass Touches to a UIButton Below it?


For an iPad app I am writing I have a container UIView with two subview that are UIView subclasses:

  • A UIImageView whose image has a portion of it cut away to reveal what is below it.
  • A UIButton below the UIImageView that is revealed through the cut away portion of the UIImageView.

Since the UIImageView overlaps the UIButton spatially it is preventing touches from reaching the UIButton even though the UIButon is fully visible due to the alpha matte cutout in the UIImageView. How do I allow the UIImageView to pass touches to it's sibling UIButton?

Thanks,
Doug


Solution

  • UIImageView usually won't block touches, UIViews do.

    You can set the userInteractionEnabled property on the overlapping views to NO, then touches should go through them.

    An other approach would be writing a custom hitTest that redirects the thouches to the button.