How to get touches when parent view has userInteractionEnabled set to NO in iOS

subchap picture subchap · Jan 11, 2011 · Viewed 14.6k times · Source

When the parent view has userInteractionEnabled=NO, its subviews will not accept touch events even if their userInteractionEnabled property is set to YES.

Is there any way to still get touch events in subviews?

Answer

Nikso picture Nikso · Nov 12, 2011

To get a view to let touches pass-through but give its subviews handle touches, let userInteractionEnabled on that view to YES and, instead, use this snippet:

-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    id hitView = [super hitTest:point withEvent:event];
    if (hitView == self) return nil;
    else return hitView;
}

Source: http://cocoaheads.tumblr.com/post/2130871776/ignore-touches-to-uiview-subclass-but-not-to-its