【问题标题】:With UIPanGestureRecognizer UINavigationController swipe to back is not working使用 UIPanGestureRecognizer UINavigationController 向后滑动不起作用
【发布时间】:2025-12-05 08:05:02
【问题描述】:

cellForRowAtIndexPath创建cell时,我还把UIPanGestureRecognizer添加到cell,并根据要求实现了所有处理。

这个Tableview包含在myViewController中,而myViewController又包含在UINavigationController中。

使用UIPanGestureRecognizer UINavigationController 向后滑动不起作用。

当用户开始从手机的最左侧滑动时,我该怎么做?它执行 UINavigationController swipe to back 而不是我的手机平移手势。

-(void)move:(PanGestureRecognizer *)gesture {

    CGPoint location = [gesture locationInView:self];
    NSIndexPath *swipedIndexPath = [self indexPathForRowAtPoint:location];
    TableViewCell *swipedCell  = [self cellForRowAtIndexPath:swipedIndexPath];
    CGRect cellRect = swipedCell.frame;

    if(location.x < 75) {
       ?????
    }

.
.
.
//my pan gesture required functionality
}


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

【问题讨论】:

    标签: ios objective-c uinavigationcontroller uipangesturerecognizer uiswipegesturerecognizer


    【解决方案1】:

    使用requireGestureRecognizerToFail

    在您的 viewController 中调用:[yourPanGesture requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer

    [cell.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([obj isKindOfClass:[UIPanGestureRecognizer class]]) {
                [obj requireGestureRecognizerToFail:interactivePopGestureRecognizer];
            }
        }];
    

    【讨论】: