设置self为导航控制器的代理,实现代理方法,在将要显示控制器中设置导航栏隐藏和显示,使用这种方式不仅完美切合滑动返回手势,同时也解决了切换tabBar的时候,导航栏动态隐藏的问题.
@interface HomePageController()
@end
@implementation HomePageController
#pragma mark - lifeCycle
- (void)viewDidLoad {
[superviewDidLoad];// 设置导航控制器的代理为selfself.navigationController.delegate=self;
}
#pragma mark - UINavigationControllerDelegate// 将要显示控制器- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated {// 判断要显示的控制器是否是自己BOOLisShowHomePage = [viewController isKindOfClass:[selfclass]];
[self.navigationControllersetNavigationBarHidden:isShowHomePage animated:YES];
}
网友评论