【问题标题】:How to disable swipe gesture in SFSafariViewController after presentViewController如何在 presentViewController 之后禁用 SFSafariViewController 中的滑动手势
【发布时间】:2025-12-11 11:25:06
【问题描述】:

我编写了以下代码来禁用 SFSafariViewController 中的滑动弹出手势。但它不起作用。

self.navigationController.interactivePopGestureRecognizer.enabled = NO;
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;

我还添加了委托方法

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

    return YES;
}

但它永远不会被调用。请帮我禁用弹出手势。

【问题讨论】:

    标签: ios objective-c iphone


    【解决方案1】:

    请覆盖presentationControllerShouldDismiss并在该方法中返回false。

    - (BOOL)presentationControllerShouldDismiss:(UIPresentationController *)presentationController{
       return NO;
    }
    

    或者您可以尝试为 SFSafariViewController 对象将 modalInPresentation 参数设置为 YES 吗?因为根据documentation 它说...

    此属性的默认值为 NO。当您将其设置为 YES 时, UIKit 会忽略视图控制器范围之外的事件并阻止 视图控制器在屏幕上时的交互解除。

    【讨论】:

    • 我继承了 SFSafariViewController 并写了 - (BOOL)presentationControllerShouldDismiss:(UIPresentationController *)presentationController{ return NO; } 但是这个委托方法没有被调用。
    • 好的,然后尝试设置 modalInPresentation=NO;在继承的类中。
    最近更新 更多