Search code examples
iosobjective-cuiviewuiresponder

iOS Receiving superview's touches events in it's subview


Question: Is there a way to receive touches from superview directly in it's subview (i.e. touches outside of subview's boundaries)?

I'd like to avoid delegation (formal/informal), NSNotification, proxy or any other intermediary solution to forward touch events from one to another view.


Solution

  • This will do the trick. Override pointInside in the subview. Hopefully direct enough for your requirements.

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
    {
       point = [self convertPoint:point toCoordinateSpace:self.superview];
        CGRect frame = self.superview.frame;
        if (CGRectContainsPoint(frame, point)) {
            return YES;
        }
        return [super pointInside:point withEvent:event];
    }