UITableView滑动手势需要近乎完美的准确性

Col*_*son 2 cocoa tableview swipe uigesturerecognizer ios

我正在为使用自定义UITableViewCell子类的UITableView开发自定义滑动事件.我把它包含UIGestureRecognizerDelegate在我的标题中,并将其包含在内viewDidLoad:

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:swipeLeft];
Run Code Online (Sandbox Code Playgroud)

我的swipeLeft方法如下所示:

-(void)didSwipe:(UISwipeGestureRecognizer *)recognizer {

    if (recognizer.state == UIGestureRecognizerStateEnded)
    {
        CGPoint swipeLocation = [recognizer locationInView:self.tableView];
        NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
        NSDictionary *clip = [self.clips objectAtIndex:swipedIndexPath.row];
        NSLog(@"Swiped!");


    }
}
Run Code Online (Sandbox Code Playgroud)

有点工作,但滑动必须非常精确.像几乎不可能精确.

我差点使用UIPanGestureRecognizer来实现它,但不幸的是它与使用全局平移手势识别器(ECSlidingViewController,感兴趣的人)的全局侧抽屉组件不太搭配.

有没有办法解决?任何帮助将不胜感激,因为我一直在谷歌搜索和浏览SO几个小时寻找解决方案.

Col*_*son 8

正如Kolin Krewinkel在Twitter上指出的那样,实现这两种委托方法就可以了:

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

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return YES;
}
Run Code Online (Sandbox Code Playgroud)