根據產品需求要求把這個介面導覽列的底線去掉,下個控制器還需要有底線.
使用下面的代碼實現
//在頁面出現的時候就將黑線隱藏起來
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
_navBarHairlineImageView.hidden = YES;
}
//在頁面消失的時候就讓navigationbar還原樣式
-(void)viewWillDisappear:(BOOL)animated{
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
//再定義一個imageview來等同於這個黑線
//UIImageView *navBarHairlineImageView;
_navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
}
//這個方法唯一的不好就是會影響導覽列的translucent(透明)屬性
//方法2:找出黑線,再做處理:
//通過一個方法來找到這個黑線(findHairlineImageViewUnder):
- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
return (UIImageView *)view;
}
for (UIView *subview in view.subviews) {
UIImageView *imageView = [self findHairlineImageViewUnder:subview];
if (imageView) {
return imageView;
}
}
return nil;
}
////同樣的在介面出現時候開啟隱藏
//-(void)viewWillAppear:(BOOL)animated
//{
// _navBarHairlineImageView.hidden = YES;
//}
////在頁面消失的時候就讓出現
-(void)viewDidAppear:(BOOL)animated
{
_navBarHairlineImageView.hidden = NO;
}