scrollView在iOS11新增的兩個(gè)屬性: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
多少;是系統(tǒng)計(jì)算得來(lái)的闭专,計(jì)算方式由contentInsetAdjustmentBehavior
決定。有以下幾種計(jì)算方式:
UIScrollViewContentInsetAdjustmentAutomatic:如果
scrollview
在一個(gè)automaticallyAdjustsScrollViewContentInset = YES
的controller
上侥涵,并且這個(gè)Controller
包含在一個(gè)navigation controller
中卖陵,這種情況下會(huì)設(shè)置在top & bottom
上adjustedContentInset = safeAreaInset + contentInset
不管是否滾動(dòng)。其他情況下與UIScrollViewContentInsetAdjustmentScrollableAxes
相同UIScrollViewContentInsetAdjustmentScrollableAxes: 在可滾動(dòng)方向上
adjustedContentInset = safeAreaInset + contentInset
侧啼,在不可滾動(dòng)方向上adjustedContentInset = contentInset
牛柒;依賴(lài)于scrollEnabled
和alwaysBounceHorizontal / vertical = YES
,scrollEnabled
默認(rèn)為yes痊乾,所以大多數(shù)情況下皮壁,計(jì)算方式還是adjustedContentInset = safeAreaInset + contentInset
UIScrollViewContentInsetAdjustmentNever:
adjustedContentInset = contentInset
UIScrollViewContentInsetAdjustmentAlways:
adjustedContentInset = safeAreaInset + contentInset
當(dāng)contentInsetAdjustmentBehavior
設(shè)置為UIScrollViewContentInsetAdjustmentNever
的時(shí)候,adjustContentInset
值不受SafeAreaInset
值的影響哪审。