@interface FSViewController () <UINavigationControllerDelegate> @end @implementation FSViewController #pragma mark - lifeCycle - (void)viewDidLoad { [super viewDidLoad]; // 設置導航控制器的代理為self self.navigationController.delegate = self; } // 將要顯示控制器 #pragma mark - UINavigationControllerDelegate - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // 判斷要顯示的控制器是否是自己 BOOL isSelf = [viewController isKindOfClass:[self class]]; [self.navigationController setNavigationBarHidden:isSelf animated:YES]; }
注意:
不推薦使用點訪問方式來設置導航欄的顯示/隱藏,因為如果在設置導航欄隱藏的同時有動畫在進行,
導航欄的位置就會出現黑色塊,這樣做是極其影響用戶體驗的!
參考資料:http://blog.csdn.net/ws1352864983/article/details/51932388
