美文网首页
swift跳转时隐藏tabbar,跳回时显示

swift跳转时隐藏tabbar,跳回时显示

作者: 择一城终老_蜗牛 | 来源:发表于2017-11-23 18:10 被阅读0次

    自定义导航

    class MainNavigationController: UINavigationController {
        
        var statusLabel: UILabel?
        
        override func viewDidLoad() {
            super.viewDidLoad()
            //导航一些基本设置
            UINavigationBar.appearance().barStyle = .default
            self.navigationBar.barTintColor = UIColor.init(hexString: "2BB465")
    //        UINavigationBar.appearance().setBackgroundImage(UIImage.init(named: "navBgImage"), for: .default)
            UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
            UINavigationBar.appearance().backIndicatorImage = UIImage(named: "c-backlt")
            UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "c-backlt")
            UINavigationBar.appearance().tintColor = UIColor.white
        }
    
    //导航初始化的一些方法
        required override init(rootViewController: UIViewController) {
            super.init(rootViewController: rootViewController)
        }
        
    //    required init?(coder aDecoder: NSCoder) {
    //        fatalError("init(coder:) has not been implemented")
    //    }
        override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
            super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        }
        
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
        }
       //*************当导航push的时候 *********************
        override func pushViewController(_ viewController: UIViewController, animated: Bool) {
       //全文重点!*********************************************************
    if self.childViewControllers.count == 1 {
              viewController.hidesBottomBarWhenPushed = true  
            }     
        //这里是返回按钮的设置
        viewController.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .done, target: nil, action: nil)
    
            super.pushViewController(viewController, animated: animated)
    
        }
    }
    

    参考:http://www.jianshu.com/p/4c94fc74f1e6

    相关文章

      网友评论

          本文标题:swift跳转时隐藏tabbar,跳回时显示

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