Tableview滑动以删除手势冲突

时间:2017-05-04 08:48:29

标签: ios tableview

在桌面视图中滑动到删除无法正常工作。在viewDidLoad中,我有以下代码。

for (UIGestureRecognizer *gesture in _addressTblView.gestureRecognizers) {
        if ([gesture isKindOfClass:[UIPanGestureRecognizer class]])
            gesture.cancelsTouchesInView = YES;
            gesture.delaysTouchesBegan = YES;
    }

我在View Controller中实现了UIGestureRecognizer方法。

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    return YES;
}

// For smooth swipe to delete in UITableView Cell, because Pan Gesture of Side Menu also competes.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    EKLog(@"gesture recognizer 1 %@", gestureRecognizer);
    EKLog(@"gesture recognizer 2 %@", otherGestureRecognizer);
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    return YES;
}

每当执行轻扫删除操作时,一个手势成功,另一个手势失败。

**gesture recognizer 1** <UIScrollViewPanGestureRecognizer: 0x1022a2ed0; state = Ended; delaysTouchesBegan = YES; delaysTouchesEnded = NO; view = <UITableView 0x10292e800>; target= <(action=handlePan:, target=<UITableView 0x10292e800>)>>
 **gesture recognizer 2** <UIScrollViewPanGestureRecognizer: 0x1022a8bc0; state = Failed; cancelsTouchesInView = NO; delaysTouchesEnded = NO; view = <UITableViewWrapperView 0x102965000>; targets= <(
        "(action=handlePan:, target=<UITableViewWrapperView 0x102965000>)",
        "(action=handleSwipeBeginning:, target=<UITableViewWrapperView 0x102965000>)"
    )>>

如调试控制台所示,两个手势识别器相互竞争。有时滑动以删除作品,有时它不会。请帮忙。谢谢。

0 个答案:

没有答案