iOS 接入Flutter禁用右滑返回关闭页面

在iOS上添加Flutter时发现Flutter页面可以通过右滑直接返回到iOS页面,而且打开三个Flutter页面也会一次性直接返回iOS页面,但是iOS页面交互中又不存在右滑返回功能,因此造成不少交互性的bug,所以把Flutter 配置成和iOS一致也禁用右键返回。

继承 FlutterViewController,然后重写viewWillAppear,在 里面配置 interactivePopGestureRecognizer isEnabled 为 false即可

 open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = true
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false;
    }

网上查的还用一种方式,但是我试的没有效果,问的iOS端也没说出个所以然,也没调出来禁用效果

    open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        let traget = self.navigationController?.interactivePopGestureRecognizer?.delegate;
        let  pan = UIPanGestureRecognizer.init(target: traget, action: nil);
//        pan.isEnabled = true;
        self.view.addGestureRecognizer(pan);
            
    }

 

上一篇:Web前端之AJAX


下一篇:3个CSS动画库,比Animated还好用,让你的网站酷炫起来