第二种方法:1)声明UIImageView变量,存储底部横线
@implementation MyViewController { UIImageView *navBarHairlineImageView;
}
2)在viewDidLoad中加入:
navBarHairlineImageView = [self findHairlineImageViewUnder:navigationBar];
3)实现找出底部横线的函数
- (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; }
4)最后在viewWillAppear,viewWillDisappear中处理
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; navBarHairlineImageView.hidden = YES; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; navBarHairlineImageView.hidden = NO; }