Question

I am using a UIPinchGestureRecognizer, which uses 2 fingers by default. If a user decides to perform the multitask gesture, the pinch gestures action is also activated.

Is there a way to cancel the pinch gesture from occurring if more than four UITouch instances are detected?

Edit Removed sample code as it was the wrong approach.

No correct solution

OTHER TIPS

Since you're not subclassing the UIPinchGestureRecognizer, you shouldn't be using touchBegan:withEvent:. Instead you should be handling it in the method that is called when a pinch occurs.

- (void)handlePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
    // if there are 2 fingers being used
    if ([pinchGestureRecognizer numberOfTouches] == 2) {
        // do stuff
    }
}

With a multitask gesture, the numberOfTouches returned by the UIPinchGestureRecognizer is 2 instead of 4 or 5, because some touches are ignored.

You can subclass UIPinchGestureRecognizer and override ignoreTouch:forEvent to cancel the recognizer if the event has 4 or 5 touches:

- (void) ignoreTouch:(UITouch*)touch forEvent:(UIEvent*)event
{
    [super ignoreTouch:touch forEvent:event];

    // Cancel recognizer during a multitask gesture
    if ([[event allTouches] count] > 3)
    {
        self.state = UIGestureRecognizerStateCancelled;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top