码迷,mamicode.com
首页 > 编程语言 > 详细

swift - 指定VC隐藏导航栏 - 禁用tabbar的根控制器手势,防止两个tabbar跳转 手势冲突

时间:2018-11-19 17:25:40      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:||   control   scan   恢复   roo   lse   deb   can   lld   

1. viewdidload 设置代理

self.navigationController?.delegate = self

  

2.代理里面指定VC 隐藏

//MARK: - 导航栏delegate
extension JYHomeViewController:UINavigationControllerDelegate {

    /// 此方法会在controller的viewWillApper方法调用后开始调用(使用时注意controller的生命周期)
    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        if viewController is JYHomeViewController || viewController is JYPhotoBrowserController || viewController is JYRTSRootViewController {
            JY_WINDOW?.removeBubbleView()
            self.navigationController?.setNavigationBarHidden(true, animated: true)
        }else{
            self.navigationController?.setNavigationBarHidden(false, animated: true)
        }
    }
}

  
3. 在根控制器首页 禁用手势, 不管有几个 homeVc, 有俩tabbar 就在俩homeVc都写上

extension JYHomeViewController: UIGestureRecognizerDelegate {
    /// 禁止使用手势返回
    func forbidhenSideBack() {
        self.isCanSideBack = false
        if (self.navigationController?.responds(to:#selector(getter: self.navigationController?.interactivePopGestureRecognizer))) == true {
            self.navigationController?.interactivePopGestureRecognizer?.delegate = self
        }
    }
    /// 恢复手势返回
    func resetSideBack() {
        self.isCanSideBack = true
        if (self.navigationController?.responds(to:#selector(getter: self.navigationController?.interactivePopGestureRecognizer))) == true {
            self.navigationController?.interactivePopGestureRecognizer?.delegate = nil
        }
    }
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return self.isCanSideBack
    }
}

  在 willappear 和willDisaapper 使用

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.forbidhenSideBack()
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.resetSideBack()
    }

  

swift - 指定VC隐藏导航栏 - 禁用tabbar的根控制器手势,防止两个tabbar跳转 手势冲突

标签:||   control   scan   恢复   roo   lse   deb   can   lld   

原文地址:https://www.cnblogs.com/qingzZ/p/9983673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!