美文网首页
iOS开发笔记-94:Swift5 - leftBarButto

iOS开发笔记-94:Swift5 - leftBarButto

作者: 原味蛋炒饭 | 来源:发表于2019-07-14 16:22 被阅读0次

OC中一遍leftBarButtonItem与右滑冲突,网上有很多代码贴出来,在自定义的UINavigationController设置一遍就可以了。

但是最近我在swift的项目中,把原先的自定义UINavigationController加入项目中使用,发现右滑返回还是无效。
这个小问题,搞了我两天……
下面是我生效的代码:

class JJNavigationVC: UINavigationController,UINavigationControllerDelegate {
    

    var popDelegate: UIGestureRecognizerDelegate?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.popDelegate = self.interactivePopGestureRecognizer?.delegate
        self.delegate = self
    }
    // MARK: - UINavigationControllerDelegate方法
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        if viewController == self.viewControllers[0] {
            self.interactivePopGestureRecognizer!.delegate = self.popDelegate
            
        } else {
            self.interactivePopGestureRecognizer!.delegate = nil
            
        }
    }

}

相关文章

网友评论

      本文标题:iOS开发笔记-94:Swift5 - leftBarButto

      本文链接:https://www.haomeiwen.com/subject/wrfikctx.html