如何将 panGestureRocgnizer 添加到 TableView,并且在正确识别平移的同时仍然让 tableview 滚动?

How can I add a panGestureRocgnizer To a TableView, and still have the tableview scroll while recognizing pans right?

我正在使用 ECSlidingViewController(github hamburger-menu/slide-out 菜单项目)。

我有一个 TableViewController,我需要将以下内容添加到我的 TableViewController。

        ECSlidingViewController *ecsVC = (ECSlidingViewController *)viewController;
        ecsVC.panGesture.delegate = self;
        [self.view addGestureRecognizer:ecsVC.panGesture];

我做不到 self.navigationcontroller.view addGestu...,因为如果我推送一个视图,我仍然会得到我不想要的 pangesture 功能。我只想要这个视图。

所以我必须self.VIEW addGest...。但是,一旦我这样做,tableView 就会停止滚动。

如果我向右平移手指,汉堡包菜单会滑出,但正如我所说,我的 tableview 不会滚动。

所以,我尝试使用 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 但我不确定我是否正确使用它。

如果我 return 是,我的汉堡菜单会滑出,但我的 tableview 不会 work/scroll。如果我 return 否,汉堡菜单不会 work/slide 出来,但 tableView 工作。

所以需要区分两者returnYES/NO

但是,如何区分呢?

我不能在 panGesture 上使用 target/action,因为那时 -gestureRecognizer:shouldReceiveTouch 永远不会被调用(这意味着我不能使 tableview 滚动)。如果我在 -gestureRecognizer:shouldReceiveTouch 中将 gestureRecognizer 转换为 UIPanGestureRecognizer,并使用 -velocityInView,因为我只得到初始点击。所以我每个只得到 0.0 的 X 和 Y。

在这种情况下如何识别用户是否向左滑动?

试试这个:

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
    CGPoint translation = [gestureRecognizer translationInView:self.view];

    if (ABS(translation.x) > ABS(translation.y)) {
        return YES;
    }

    return NO;
}