aleclarson aleclarson - 4 months ago 33
iOS Question

How can I make touch events pass through a UIView (similar to pointer-events:none in CSS)?

In CSS,

pointer-events:none;
allows click events to pass through an element. I'm curious if there is anything similar that I can do in Objective-C on iOS for
UIView
s.

Here's a jsfiddle to an example of pointer-events: none.

Could I somehow achieve the same behavior for a
UIView
by overriding
hitTest:withEvent:
? Or maybe there is another way to do this?

Thanks for any help.

Answer

What you're looking for is commonly called "Event Bubbling".

You may refer to the Apple docs here: https://developer.apple.com/library/ios/documentation/eventhandling/conceptual/eventhandlingiphoneos/eventhandlingiphoneos.pdf (Read the Event Delivery: The Responder Chain Section)

So your basic instinct was right, you in fact do need utilize hitTest:withEvent:, but you can further customize things by hooking up into the Responder chain. That section has a very neat example.

Comments