在NavigationController中重寫下面方法,來實現(xiàn)隱藏tabBar很常見,但是今天sb了,把 super.pushViewController(viewController, animated: animated)寫方法開始了,導(dǎo)致怎么也隱藏不了,我都快跳樓了,浪費了半小時的時間,特此記錄下來,以防坑到別的道友。。。
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,一定要寫到這個方法最后?。?!
另外記錄下NavigationBar隱藏的錯誤姿勢
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)當右劃返回手勢滑到一半沒有返回,NavigationBar會出來,尷尬??
所以正確的方式是
override func viewDidAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
最近發(fā)現(xiàn)navBar很坑,因為手勢問題會偶發(fā)界面卡死的問題,還有莫名其妙的隱藏顯示失敗,所以全部自定義掉最靠譜