// 以前在每个页面的 didload ... viewwillapper viewwilldisapper 写了无数这句话,各个页面乱七八糟
self.navigationController.navigationBar.hidden = xx;
// 右划返回出现前还没啥问题,自从出了右划返回简直坑不要太狠~(黑边)
// 以为很简单的bug结果搞了半天。。。。
解决方案
// BaseViewController中
/**
* nav的代理指向自己,实现代理方法
* [self.navigationController setNavigationBarHidden: animated: animated];
替代self.navigationController.navigationBar.hidden = xx;
*/
@interface KapBaseViewController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate>
@end
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.delegate = self;
}
#pragma mark - Private Methods
#pragma mark -
#pragma mark Whether need Navigation Bar Hidden
- (BOOL) needHiddenBarInViewController:(UIViewController *)viewController {
BOOL needHideNaivgaionBar = NO;
// 自定义哪些页面需要隐藏
if ([viewController isKindOfClass: NSClassFromString(@"ViewController")] ||
[viewController isKindOfClass: NSClassFromString(@"KapMakeImageViewController")]) {
needHideNaivgaionBar = YES;
}
return needHideNaivgaionBar;
}
#pragma mark - UINaivgationController Delegate
#pragma mark -
#pragma mark Will Show ViewController
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[navigationController setNavigationBarHidden: [self needHiddenBarInViewController: viewController]
animated: animated];
}
抄袭自原文
参考stackoverflow