在NavigationController中重寫下面方法捺僻,來實(shí)現(xiàn)隱藏tabBar很常見镣陕,但是今天sb了邮旷,把 super.pushViewController(viewController, animated: animated)寫方法開始了累舷,導(dǎo)致怎么也隱藏不了,我都快跳樓了壤圃,浪費(fèi)了半小時(shí)的時(shí)間陵霉,特此記錄下來,以防坑到別的道友伍绳。踊挠。。
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if viewControllers.count > 0 {
viewController.hidesBottomBarWhenPushed = true
}
super.pushViewController(viewController, animated: animated)
}
super.pushViewController(viewController, animated: animated),這句一定要寫最后冲杀,如果這句寫在方法的開始效床,他的子界面里再設(shè)置viewController.hidesBottomBarWhenPushed = true,會完全不起作用漠趁,所以super扁凛,一定要寫到這個(gè)方法最后!4炒谨朝!
另外記錄下NavigationBar隱藏的錯(cuò)誤姿勢
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
如果隱藏掉NavigationBar,右劃返回就不起作用甥绿,需要設(shè)置
navigationController?.interactivePopGestureRecognizer?.delegate = self as? UIGestureRecognizerDelegate;
這樣右劃返回手勢就起作用了字币,但是如果設(shè)置上面的隱藏NavigationBar的方式會發(fā)現(xiàn)當(dāng)右劃返回手勢滑到一半沒有返回,NavigationBar會出來共缕,尷尬??
所以正確的方式是
override func viewDidAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
最近發(fā)現(xiàn)navBar很坑洗出,因?yàn)槭謩輪栴}會偶發(fā)界面卡死的問題,還有莫名其妙的隱藏顯示失敗图谷,所以全部自定義掉最靠譜