方法一
- (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;
}
该方法在iOS 11时会闪退,在iOS 11上[self.navigationController.navigationBar subviews]为空
方法二
- (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];
}
使用方法二时,如果返回上一页的方法是带动画的,在进入到上一页界面时,导航的颜色是渐变
个人感觉:方法一比方法二更好用,效果也比较好