UIButton inside a view that has a UITapGestureRecognizer

You can set your controller or view (whichever creates the gesture recognizer) as the delegate of the UITapGestureRecognizer. Then in the delegate you can implement -gestureRecognizer:shouldReceiveTouch:. In your implementation you can test if the touch belongs to your new subview, and if it does, instruct the gesture recognizer to ignore it. Something like the following:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    // test if our control subview is on-screen
    if (self.controlSubview.superview != nil) {
        if ([touch.view isDescendantOfView:self.controlSubview]) {
            // we touched our control surface
            return NO; // ignore the touch
        }
    }
    return YES; // handle the touch
}

Leave a Comment