先直接上方法:
隐藏:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
}
显示:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = nil;
}
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
苹果官方文档上解释黑线的原因: