去掉导航栏self.navigationController.navigationBar下默认黑线。
方法一:(会影响导航栏的translucent透明属性)
//视图将要显示时隐藏
-(void)viewWillAppear:(BOOL)animated
{
[superviewWillAppear:animated];
[self.navigationController.navigationBarsetBackgroundImage:[UIImagenew]forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBarsetShadowImage:[UIImagenew]];
}
//视图将要消失时取消隐藏
-(void)viewWillDisappear:(BOOL)animated
{
[superviewWillDisappear:animated];
[self.navigationController.navigationBarsetBackgroundImage:nilforBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBarsetShadowImage:nil];
}
方法二:
@property(nonatomic, weak)UIImageView*lineView;
//视图加载完成获取到导航栏最下面的黑线
- (void)viewDidLoad {
[superviewDidLoad];
//获取导航栏下面黑线
_lineView = [selfgetLineViewInNavigationBar:self.navigationController.navigationBar];
}
//视图将要显示时隐藏
- (void)viewWillAppear:(BOOL)animated
{
[superviewWillAppear:animated];
_lineView.hidden=YES;
self.navigationController.navigationBar.translucent=YES;
self.navigationController.navigationBar.barTintColor= [UIColorwhiteColor];
}
//视图将要消失时取消隐藏
- (void)viewWillDisappear:(BOOL)animated
{
[superviewWillDisappear:animated];
_lineView.hidden=NO;
self.navigationController.navigationBar.translucent=NO;
self.navigationController.navigationBar.barTintColor= [UIColorblackColor];
}
//找到导航栏最下面黑线视图
- (UIImageView*)getLineViewInNavigationBar:(UIView*)view
{
if([viewisKindOfClass:UIImageView.class] && view.bounds.size.height<=1.0) {
return(UIImageView*)view;
}
for(UIView*subview in view.subviews) {
UIImageView*imageView = [selfgetLineViewInNavigationBar:subview];
if(imageView) {
returnimageView;
}
}
returnnil;
}