iOS 11.0中不推荐使用'automatedAdjustsScrollViewInsets'

Lep*_*ron 58 xcode deprecated ios swift

我刚刚开始编译到iOS 11,并注意到Apple现在宣布该属性

var automaticallyAdjustsScrollViewInsets: Bool { get set }
Run Code Online (Sandbox Code Playgroud)

被弃用:

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

在此输入图像描述

是否有其他属性可以在iOS 11中修复此警​​告?

默认值是否保持正确或将来如何处理?

小智 92

此代码可能有所帮助:

if #available(iOS 11.0, *) {
    scrollView.contentInsetAdjustmentBehavior = .never
} else {
    automaticallyAdjustsScrollViewInsets = false
}
Run Code Online (Sandbox Code Playgroud)

  • @AlexeyStrakh scrollView是任何调整了插图的`UIScrollView`.例如,在`UICollectionViewController`上它将是`self.collectionView`,在`UITableViewController`上它将是`self.tableView`. (3认同)

tot*_*tiG 77

此属性的默认值现在为true.如果需要设置它,则需要在将承载viewController的scrollview中设置它并设置其属性contentInsetAdjustmentBehavior.以下是一个例子:

scrollView.contentInsetAdjustmentBehavior = .automatic
Run Code Online (Sandbox Code Playgroud)

  • 虽然我使用".never"因为我把它设置为假,这个似乎是正确的替代品!谢谢. (10认同)
  • @RajasekharPasupuleti `scrollView.contentInsetAdjustmentBehavior = .never` (4认同)

小智 5

您也可以在 Interface Builder 中进行设置。选择您的 tableView 或 collectionView,然后从 Size Inspector 的下拉列表中选择 .never for 'Content Insets Adjustment Behavior'

尺寸检查员