“自动调整 ScrollViewInsets”在 iOS 11.0中不被推崇

我刚开始编译 iOS11,注意到苹果公司现在宣布了这个属性

var automaticallyAdjustsScrollViewInsets: Bool { get set }

被贬低为:

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

enter image description here

在 iOS11中是否有其他属性来修复这个警告?

默认值是否仍然为真,或者将来如何处理这个问题?

52673 次浏览

The default for this property is now true. If you need to set this, you will need to set it in the scrollview that would host the viewController and set its property contentInsetAdjustmentBehavior. Below is an example:

scrollView.contentInsetAdjustmentBehavior = .automatic

This code may help:

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

You can also set this in Interface Builder. Select your tableView or collectionView then select from the drop-down in the Size Inspector select .never for 'Content Insets Adjustment Behavior'

Size Inspector

For those who are wanting to adjust this from an objective-c perspective, here is the code:

self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever