一、當 A 頁面要 push 到 B 頁面,且需要隱藏 B 頁面的導航欄時,只需在 A 頁面覆寫以下兩個方法:
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true, animated: true) } override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) self.navigationController?.setNavigationBarHidden(false, animated: true) }
注意:若用 self.navigationController?.navigationBarHidden = false 直接賦值,在隱藏與未隱藏導航欄的控制器之間切換時,導航欄可能出現閃動。改用上面的 setNavigationBarHidden:animated: 方法呼叫,就能解決這個問題。
二、當從 A 頁面 push 跳轉到 B 頁面需要隱藏 tabBar 時,在 A 頁面寫如下程式碼:
self.hidesBottomBarWhenPushed=YES; BViewController *bvc=[[BViewController alloc]init]; [self.navigationController pushViewController:bvc animated:YES]; self.hidesBottomBarWhenPushed=NO; //最後一句話,可以保證在back回到A時,tabBar會恢復正常顯示
關鍵在於 hidesBottomBarWhenPushed 屬性:在 push 之前設為 YES 即可隱藏目標頁的 tabBar,push 完成後再設回 NO,確保返回時 tabBar 能正常顯示。以上就是本文的全部內容,希望對大家有所幫助。