How to make a superview intercept button touch events?

I’d be interested in seeing other solutions, but the easiest way I know of is to override either of these two UIView methods:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;

These methods get called to determine if the touch is within the bounds of the view or any of its subviews, so this is a good point to intercept the touch and then pass it on. Just do what ever you want, and then

return [super hitTest:point withEvent:event];

or

return [super pointInside:point withEvent:event];

Leave a Comment