0

我有一个 UITableViewCell 的自定义实现。UITableViewCell 可以向左或向右滑动。我同样使用 UIPanGestureRecognizer。

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
    }
}

现在我希望能够在整个屏幕上支持两指滑动,这样即使在 UITableViewCell 上进行两指滑动,也不会触发上述代码。我怎样才能做到这一点?

4

1 回答 1

1

如果maximumNumberOfTouches将手势识别器上的 设置为1,它将不再接受多指滑动:

UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
recognizer.maximumNumberOfTouches = 1;
于 2013-06-08T03:06:10.780 回答