美文网首页UI布局
iOS 解决scrollView自动距离顶部空白(stateVi

iOS 解决scrollView自动距离顶部空白(stateVi

作者: 崠崠 | 来源:发表于2018-07-10 17:06 被阅读0次

    当页面隐藏navigationBar[self.navigationController setNavigationBarHidden:YES];
    期望整个view填充window的时候,会发现存在scrollView的情况下,顶部会自动留出stateView高度的距离。例如,下方是tableView的情况:

    scrollViewInsets.png

    总的解决方案:

    if (@available(iOS 11.0, *)) {
            self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
    

    也有另一种解决思路,就是在顶部增加一个view(非scrollView),下方的scrollView不会自动留出空隙


    view填充顶部.png

    问题:手势左滑返回上一级,navigationBar出现异常

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [self.navigationController setNavigationBarHidden:YES ];
    }
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        [self.navigationController setNavigationBarHidden:NO ];
    }
    

    具体表示:


    navigationBar异常.gif

    改为

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
    
    navigationBar正常.gif

    相关文章

      网友评论

        本文标题:iOS 解决scrollView自动距离顶部空白(stateVi

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