情景:?一級頁面不顯示導航欄 ,二級頁面顯示導航欄.
方法一 適用于push/pop:
一級頁面中?
- (void)viewWillAppear:(BOOL)animated {
? ? [super viewWillAppear:animated];
? ? [self.navigationController setNavigationBarHidden:YES animated:animated];
}- (void)viewWillDisappear:(BOOL)animated {
? ? [super viewWillDisappear:animated];
? ? [self.navigationController setNavigationBarHidden:NO animated:animated];
}
方法二(都適用):
?設置self為導航控制器的代理,實現(xiàn)代理方法,在將要顯示控制器中設置導航欄隱藏和顯示,使用這種方式不僅完美切合滑動返回手勢,同時也解決了切換tabBar的時候,導航欄動態(tài)隱藏的問題.
@interface HomePageController ()
@end
@implementation HomePageController
#pragmamark - lifeCycle
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? // 設置導航控制器的代理為
selfself.navigationController.delegate= self;
}#pragmamark - UINavigationControllerDelegate// 將要顯示控制器- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
? ? // 判斷要顯示的控制器是否是自己BOOL isShowHomePage = [viewController isKindOfClass:[selfclass]];
? ? [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
寫個基類viewcontroller待讳,只要在基類viewcontroller中:
- (void)viewWillAppear:(BOOL)animated {
? ? [super viewWillAppear:animated];
? ? [self.navigationController setNavigationBarHidden:self.navigationHidden animated:animated];
}