Translucent: 是否半透明 (默认YES)
1. translucent为NO时:
edgesForExtendedLayout属性指定边缘延伸的方向,默认为UIRectEdgeAll,四周边缘均延伸。此时所有控制器的view不会延伸到navigationbar(包含statebar)和 tabbar 的覆盖区域
2. translucent为YES时:
edgesForExtendedLayout属性为默认(UIRectEdgeAll)时,所有控制器的view都会延伸到navigationbar(包含statebar)和tabbar覆盖的区域,如果不想延伸到覆盖区域可以设置edgesForExtendedLayout为UIRectEdgeNone
-
对于滚动视图
①
automaticallyAdjustsScrollViewInsets = YES可自动调整内容至未被navigationbar(包含statebar)和tabbar覆盖的区域,即给navigationbar(包含statebar)和tabbar覆盖的区域预留出空白,默认为YES。②
automaticallyAdjustsScrollViewInsets = NO,滚动视图的内容仍会随着view延伸到navigationbar(包含statebar)和tabbar覆盖的区域③ 若
edgesForExtendedLayout属性置为UIRectEdgeNone,控制器的view延伸到navigationbar(包含statebar)和tabbar就不会延伸,且滚动视图也不会给navigationbar(包含statebar)和tabbar覆盖的区域预留出空白 -
对于非滚动视图
①
automaticallyAdjustsScrollViewInsets属性设置无效
② 若edgesForExtendedLayout属性设置为UIRectEdgeNone,控制器的view延伸到navigationbar和tabbar就不会延伸
当translucent和edgesForExtendedLayout为默认值时视图控制器的View会延伸到navigationbar和Tabbar底下,如图1
图1.png
当navigationbar和Tabbar的Translucent都设置为NO时,如图2
图2.png
3. automaticallyAdjustsScrollViewInsets 和 contentInsetAdjustmentBehavior
1. automaticallyAdjustsScrollViewInsets
条件:iOS 9.0、translucent(YES)、edgesForExtendedLayout(UIRectEdgeNoneAll)
1. automaticallyAdjustsScrollViewInsets = YES (默认)
图3.png
tableView 的大小为全屏大小 但是内容会从导航栏底下开始 并且在工具栏上面停止,即(自动调整内容大小不被导航栏和工具栏遮挡)
2. automaticallyAdjustsScrollViewInsets = NO
图4.png
tableView 的大小为全屏大小,内容视图也为全屏大小 会被导航栏和工具栏遮住内容
2. contentInsetAdjustmentBehavior
在iOS11 中, UIViewController的automaticallyAdjustsScrollViewInsets属性已经不再使用,我们需要使用UIScrollView的 contentInsetAdjustmentBehavior` 属性来替代它.
UIScrollViewContentInsetAdjustmentBehavior 是一个枚举类型,值有以下几种:
-
automatic和scrollableAxes一样,scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距. -
scrollableAxes自动计算内边距. 在scrollView不可滚动时,不会自动计算(会被导航栏和工具栏遮住) -
never不计算内边距 -
always根据safeAreaInsets 计算内边距
条件tableView.scrollEnabled = NO
1. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
图5
2. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentScrollableAxes
图6.png
;












网友评论