代码很简单,只需写一个继承UIViewController的基类BasisController
BasisController.h
#import <UIKit/UIKit.h>
@interface BasisController : UIViewController
///是否隐藏导航栏
@property (nonatomic, assign) BOOL hideNavBar;
@end
BasisController.m
#import "BasisViewController.h"
@interface BasisController ()
@end
@implementation BasisController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:self.hideNavBar animated:animated];
}
@end
需要隐藏导航栏的VC继承BasisController,然后设置self.hideNavBar = YES
就可以了,这种方法只对当前页面生效,不会影响到后面的页面,并且在切换tabbar、滑动返回、push、present时导航栏不会有任何的闪烁、跳动等异常动画。