문제

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.

올바른 솔루션이 없습니다

다른 팁

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;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top