iosNav 黑线问题

参考文章
方法一:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if (_navBarHairlineImageView == nil) {
        _navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationBar];
    }
    _navBarHairlineImageView.hidden = YES;
}


//通过一个方法来找到这个黑线(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)viewWillAppear:(BOOL)animated
{
 navBarHairlineImageView.hidden = NO;
}

方法二:

//在页面出现的时候就将黑线隐藏起来
-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
//在页面消失的时候就让navigationbar还原样式
-(void)viewWillDisappear:(BOOL)animated{
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

你可能感兴趣的:(iosNav 黑线问题)