- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//去掉导航栏底部的黑线
self.navigationController.navigationBar.shadowImage = [UIImage new];
}
如果仅设置当前页导航透明,需加入下面方法 - (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
}
需要注意的是:如果返回上一页的操作有动画,则在上一页出现的时候,导航栏的颜色会逐渐变化
方法二
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 0;
}
仅设置当前页面 - (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 1;
}