美文网首页
automaticallyAdjustsScrollViewIn

automaticallyAdjustsScrollViewIn

作者: airpoet | 来源:发表于2017-06-27 00:11 被阅读0次

automaticallyAdjustsScrollViewInsets大家肯定熟悉了,也遇到过类似的坑(tableView或scrollView的莫名其妙的偏移)通过设置该属性的值(automaticallyAdjustsScrollViewInsets =NO)填坑的。有人会问,我就没设置该属性的值(automaticallyAdjustsScrollViewInsets =NO)为什么没有偏移呢?又有人会问,怎么有时候偏移的高度不一样?有时候20,有时候64?

注意:1)只有根视图的第一个子视图是scrollView automaticallyAdjustsScrollViewInsets=YES才有用。

2)当隐藏导航栏,scrollView的contentInset的top为20,如果再隐藏状态栏contentInset的top为0。

ios 6到ios 7,viewController的根view的起始点做了调整,(0,64)--->(0,0)。这样的改变导致一个问题,scrollView有64像素的大小被导航栏挡着了。苹果早就想到了,所以主角上场了,同样ios 7出来的新属性automaticallyAdjustsScrollViewInsets,苹果默认自动设置了scrollView的contentInset来适配屏幕以达到不被导航栏挡着。

最终,为了更好的避免这个坑,推荐scrollView好的设置frame方法:automaticallyAdjustsScrollViewInsets ==NO,frame = (0,64,320,568)【5s为例】

相关文章

网友评论

      本文标题:automaticallyAdjustsScrollViewIn

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