项目中我们经常会遇到这个问题,比如页面A没有导航栏,页面B有导航栏,那么如果从A push到B 或者从B返回到A时, Navc不合时宜的出现或消失会让交互变的很突兀,以下提供一种解决方法
- 首先,我们先写一个继承自UINavigationController的BaseNavigationController类,并将所关联到的Navc替换成BaseNavigationController,然后重写pushViewController: animated:方法,如下
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
[self setNavigationBarHidden:NO animated:YES];
}
- 然后在需要隐藏导航栏的界面的viewWillAppear:方法中添加如下代码
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
至此,问题解决.