scrollView在iOS11新增的两个属性:adjustContentInset 和 contentInsetAdjustmentBehavior。
/* When contentInsetAdjustmentBehavior allows, UIScrollView may incorporate
its safeAreaInsets into the adjustedContentInset.
*/
@property(nonatomic, readonly) UIEdgeInsets adjustedContentInset API_AVAILABLE(ios(11.0),tvos(11.0));
adjustContentInset
表示contentView.frame.origin
偏移了scrollview.frame.origin
多少;是系统计算得来的,计算方式由contentInsetAdjustmentBehavior
决定。有以下几种计算方式:
UIScrollViewContentInsetAdjustmentAutomatic:如果
scrollview
在一个automaticallyAdjustsScrollViewContentInset = YES
的controller
上,并且这个Controller
包含在一个navigation controller
中,这种情况下会设置在top & bottom
上adjustedContentInset = safeAreaInset + contentInset
不管是否滚动。其他情况下与UIScrollViewContentInsetAdjustmentScrollableAxes
相同UIScrollViewContentInsetAdjustmentScrollableAxes: 在可滚动方向上
adjustedContentInset = safeAreaInset + contentInset
,在不可滚动方向上adjustedContentInset = contentInset
;依赖于scrollEnabled
和alwaysBounceHorizontal / vertical = YES
,scrollEnabled
默认为yes,所以大多数情况下,计算方式还是adjustedContentInset = safeAreaInset + contentInset
UIScrollViewContentInsetAdjustmentNever:
adjustedContentInset = contentInset
UIScrollViewContentInsetAdjustmentAlways:
adjustedContentInset = safeAreaInset + contentInset
当contentInsetAdjustmentBehavior
设置为UIScrollViewContentInsetAdjustmentNever
的时候,adjustContentInset
值不受SafeAreaInset
值的影响。