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

2017-11-23  本文已影响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

上一篇下一篇

猜你喜欢

热点阅读