美文网首页
iOS隐藏导航栏下面的黑线

iOS隐藏导航栏下面的黑线

作者: i_promise | 来源:发表于2018-03-16 10:08 被阅读21次
    - (void)viewWillAppear:(BOOL)animated{
        
        [super viewWillAppear:animated];
        //隐藏黑线
        [self useMethodToFindBlackLineAndHindWithHidden:YES];
    
    }
    
    - (void)viewWillDisappear:(BOOL)animated{
        
        [super viewWillDisappear:animated];
        //显示黑线
        [self useMethodToFindBlackLineAndHindWithHidden:NO];
    
    }
    
    - (void)useMethodToFindBlackLineAndHindWithHidden:(BOOL)hidden{
        
        UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
        //隐藏黑线(在viewWillAppear时隐藏,在viewWillDisappear时显示)
        blackLineImageView.hidden = hidden;
        
    }
    
    - (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;
    }
    
    

    相关文章

      网友评论

          本文标题:iOS隐藏导航栏下面的黑线

          本文链接:https://www.haomeiwen.com/subject/kmbcqftx.html