我有一个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上完成两个手指滑动,也不会触发上述代码。 我怎样才能做到这一点?
答案 0 :(得分:1)
如果您将手势识别器上的maximumNumberOfTouches
设置为1
,则它将不再接受多指滑动:
UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
recognizer.maximumNumberOfTouches = 1;