简体   繁体   English

如何在UIViewController中禁用拖动关闭

[英]How disable drag dismiss in UIViewController

I have UIViewController add to my view by present. 我现在有UIViewController添加到我的视图。 Now user can remove this view by drag to bottom of screen. 现在,用户可以通过拖动到屏幕底部来删除该视图。 How can I disable it? 如何禁用它?

I try by 我尝试

view.isUserInteractionEnabled = false

and

override func viewDidLoad() {
        self.transitioningDelegate = self
    }

extension MyViewController: UIViewControllerTransitioningDelegate {
    func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return nil
    }

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return nil
    }
}

But user still can dismiss it. 但是用户仍然可以将其关闭。

您需要禁用平移手势才能禁用拖动关闭。

You can use this line in the viewController's viewDidLoad method: 您可以在viewController的viewDidLoad方法中使用以下行:

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

You can refer this . 你可以参考这个

See Bilal's answer here 在这里查看Bilal的答案

.isModalInPresentation = true worked for me .isModalInPresentation = true对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM