iOS. Make UIPinchGestureRecognizer dominant over UITapGestureRecognizer?

209 Views Asked by At

it means user can't pan and pinch simultaneously and pinch gesture stops pan one.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    return YES;
}

This code is not working for me because it makes these gestures working simultaneously.

By default if I don't use this code then pan gesture stops pinch one but I need the opposite thing.

Updated

@interface SomeClass : UIViewController <UIGestureRecognizerDelegate>

...

@end

@implementation SomeClass

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

        return YES;
    }

@end
2

There are 2 best solutions below

0
On BEST ANSWER

solved by editing pan gesture handler:

- (IBAction)panGRUsed:(id)sender {

    UIPanGestureRecognizer *gr = (UIPanGestureRecognizer *)sender;
    if (gr.numberOfTouches > 1) {

        [gr setTranslation:CGPointZero inView:self.view];
    } else {

        ...
    }
}
1
On

You can create dependencies between recognizers using the requireGestureRecognizerToFail: method so that one gesture will only become eligible to begin when another has failed.

Depending on exactly what you need you may have to subclass and create your own gestures so that you can control how and when they begin and fail.