KalyanChakravarthy.net

home photos apps about

Propogating iOS Gestures to parent views

Thu 25 September 2014

If a custom UIView adds UITapGestureRecognizer to one of its elements for example say tracking, the default behaviour would prevent it from the gesture being propogated it to its parent views which may be listening for the same gesture.

Gesture propogation can be ensured simply by implementing a UIGestureRecognizerDelegate method.

- (void)setup {
    UITapGestureRecognizer *gestuer = [[UITapGestureRecognizer alloc] init];
    gesture.delegate = self;
}

#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

Unlike other solutions, this does not reqire the UIView subclass to be aware of the existence any other gesture recognizers.