@available(iOS, introduced: 7.0, deprecated: 11.0)
open var automaticallyAdjustsScrollViewInsets: Bool // Defaults to YES
此方法在iOS 11后被棄用, 取而代之的新屬性為:
/* Configure the behavior of adjustedContentInset.
Default is UIScrollViewContentInsetAdjustmentAutomatic.
*/
@available(iOS 11.0, *)
open var contentInsetAdjustmentBehavior: UIScrollViewContentInsetAdjustmentBehavior
UIScrollViewContentInsetAdjustmentBehavior
是一個(gè)新的枚舉, 由于iPhoneX的存在, 為了適配齊劉海兒
的safe area
而新增的屬性, 專門用于ScrollView
自動(dòng)調(diào)整contentInset
. 具體的枚舉成員如下:
public enum UIScrollViewContentInsetAdjustmentBehavior : Int {
case automatic // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
case scrollableAxes // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
case never // contentInset is not adjusted
case always // contentInset is always adjusted by the scroll view's safeAreaInsets
}
解決問(wèn)題:
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .automatic
} else {
automaticallyAdjustsScrollViewInsets = false
}