newbie
newbie

Reputation: 1059

swipe with one finger and two finger swipe on the same UIView subclass

I have a custom implementation of UITableViewCell. The UITableViewCell can be swiped to the left or the right. I use a UIPanGestureRecognizer for the same.

UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
        recognizer.delegate = self;
        [self addGestureRecognizer:recognizer];

           }

#pragma mark - horizontal pan gesture methods
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
    CGPoint translation = [gestureRecognizer translationInView:[self superview]];
    // Check for horizontal gesture
    if (fabsf(translation.x) > fabsf(translation.y)) {
        return YES;
     }
    return NO;
}

-(void)handlePan:(UIPanGestureRecognizer *)recognizer {
    if (recognizer.state == UIGestureRecognizerStateBegan) {
    // if the gesture has just started, record the current centre location
        // SOME CODE
    }

    if (recognizer.state == UIGestureRecognizerStateChanged) {
        // translate the center
        //SOME CODE
    }

    if (recognizer.state == UIGestureRecognizerStateEnded) {
        // the frame this cell would have had before being dragged
        //SOME CODE
    }
}

Now I want to be able to support two finger swipe on on the entire screen such that even if a two finger swipe is done on a UITableViewCell, the above code is not triggered. How can I achieve this ?

Upvotes: 0

Views: 165

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726539

If you set the maximumNumberOfTouches on your gesture recognizer to 1, it will no longer accept multi-finger swipes:

UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
recognizer.maximumNumberOfTouches = 1;

Upvotes: 1

Related Questions