Krzysztof Przygoda
Krzysztof Przygoda

Reputation: 1315

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.

Upvotes: 2

Views: 559

Answers (1)

foundry
foundry

Reputation: 31745

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];
}

Upvotes: 1

Related Questions