美文网首页
tableView.contentInsetAdjustment

tableView.contentInsetAdjustment

作者: EmptyWalker | 来源:发表于2018-06-21 11:46 被阅读153次

    在iOS11中,如果想是实现tableview从最顶部开始显示,需要先将navigationBar设置为透明,然后设置UIScroller的contentInsetAdjustmentBehavior为never,但我在代码中添加一下代码,缺不能实现对应的效果

    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    navigationController?.navigationBar.shadowImage = UIImage()
    navigationController?.navigationBar.tintColor = .white
    tableView.contentInsetAdjustmentBehavior = .never
    

    效果如下:


    image.png

    很明显tableview并没有从顶部开始绘制,我翻了很多资料都没有找出答案。

    解决过程

    由于我的项目是用Interface Builder创建的,就去查看了我的代码约束,看到约束如下


    image.png

    顶部的约束是距离Safe Area.Top 0pt,因为有安全区的存在,所以tableview的顶部无法从屏幕最顶端开始显示。

    解决方法

    将顶部约束的Second Item 选择为Supre View,然后constant设为0即可,设置如下:


    image.png

    效果如下:


    image.png

    相关文章

      网友评论

          本文标题:tableView.contentInsetAdjustment

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