在iOS開發中,特別是一些首頁展現上要去掉導航欄(UINavigationBar)。 最簡單的辦法在- (void)viewWillAppear:(BOOL)animated方法中直接設置隱藏導航欄,在(void)viewWillDisappear:(BOOL)animated方法中在顯示出導航欄app
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:YES]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; }
可是這樣會出現一個問題,就是切換到這個界面的時候,會出現整個界面上移的效果,體驗不是很好,解決這個問題其實很簡單,只須要兩句話 第一步 在BaseNavigationController.m中複寫這個方法code
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated { [super pushViewController:viewController animated:animated]; [self setNavigationBarHidden:NO animated:YES];
第二步 在須要隱藏導航欄的.m文件的開發
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:YES animated:YES]; }