iOS11的automaticallyAdjustsScrollViewInsets变动

@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是一个新的枚举, 由于iPhoneX的存在, 为了适配齐刘海儿safe area而新增的属性, 专门用于ScrollView自动调整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
}

解决问题:

if #available(iOS 11.0, *) {
        tableView.contentInsetAdjustmentBehavior = .automatic
    } else {
        automaticallyAdjustsScrollViewInsets = false
    }

你可能感兴趣的:(iOS11的automaticallyAdjustsScrollViewInsets变动)