1.属性edgesForExtendedLayout
if (kIOSVersion >= 7.0) {
// self.automaticallyAdjustsScrollViewInsets = NO;
self.edgesForExtendedLayout = UIRectEdgeNone; // 让layout不要全部扩充直至顶部
self.navigationController.navigationBar.translucent = NO;// 由于self.edgesForExtendedLayout = UIRectEdgeNone的原因,导航栏此时会变灰,所以得加上这一句(关闭半透明)
}
2.extendedLayoutIncludesOpaqueBars属性则用来控制在导航栏不透明的情况下,layout是否要拓展。所以前提条件是导航栏不透明,即:
self.navigationController.navigationBar.translucent = NO // 关闭系统默认的半透明
在这个条件下再设置
self.extendedLayoutIncludesOpaqueBars = NO;
即可达到不让layout拓展至顶部的效果,即此时坐标原点在导航栏下面。
注意:在self.navigationController.navigationBar.translucent = Yes(默认)情况下,extendedLayoutIncludesOpaqueBars这个属性不起任何作用。
3.属性automaticallyAdjustsScrollViewInsets
这其实改变的是scrollIndicatorInsets这个属性,而不是frame。
另外再说一点,这个automaticallyAdjustsScrollViewInsets的属性,只对加在self.view上的第一个子视图起作用,所以我们可以在将UIScrollView加载到self.view上之前先加载一个其他控件,这样也能达到同样的效果。如下面效果图:
1.gif









网友评论