'automaticallyAdjustsScrollViewInsets' 在 iOS 11.0 中被弃用

'automaticallyAdjustsScrollViewInsets' was deprecated in iOS 11.0

我刚开始编译到 iOS 11,注意到 Apple 现在声明了 属性

var automaticallyAdjustsScrollViewInsets: Bool { get set }

已弃用:

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621372-automaticallyadjustsscrollviewin

在 iOS 11 中是否有另一个 属性 来修复此警告?

默认值会保持不变还是将来会如何处理?

此 属性 的默认值现在为真。如果您需要设置它,您将需要在承载 viewController 的滚动视图中设置它并设置它的 属性 contentInsetAdjustmentBehavior。下面是一个例子:

scrollView.contentInsetAdjustmentBehavior = .automatic

此代码可能有帮助:

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

您也可以在 Interface Builder 中进行设置。 Select 您的 tableView 或 collectionView 然后 select 从大小检查器 select 的下拉列表中选择。从不 'Content Insets Adjustment Behavior'

对于那些想从objective-c角度进行调整的人,这里是代码:

self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever