iOS Swift左边边缘侧滑返回退出当前界面

2022-01-07  本文已影响0人  Lee坚武

更多方法交流可以家魏鑫:lixiaowu1129,一起探讨iOS相关技术!
首先,viewdidload方法里面添加手势

//加载前端webview
    override func viewDidLoad() {
        super.viewDidLoad()
        NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(applicationWillResignActive), name: UIApplication.willResignActiveNotification, object: nil)
        clearCache()   //加载URL每次都清理缓存
        setUI()
        loadURLView()
        ///添加侧滑手势
        view.backgroundColor = .clear
        let pan = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(slide(leftSide:)))
        pan.edges = .left
        view.addGestureRecognizer(pan)
    }

添加实现手势的方法

    ///手势左边侧滑关闭UI
    @objc func slide(leftSide: UIPanGestureRecognizer){
        if isCanGoBack == false && urlOrExit == "exit" {
//            self.webView.goBack()
            self.antDismissViewController()
        }else{
//            self.antDismissViewController()
            self.webView.goBack()
        }
    }
上一篇下一篇

猜你喜欢

热点阅读