iOS 11.0中不推荐使用'automatedAdjustsScrollViewInsets'

问题描述 投票:50回答:3

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

var automaticallyAdjustsScrollViewInsets: Bool { get set }

被弃用:

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

enter image description here

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

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

ios swift xcode deprecated
3个回答
71
投票

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

scrollView.contentInsetAdjustmentBehavior = .automatic

85
投票

此代码可能有所帮助:

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

2
投票

您也可以在Interface Builder中进行设置。选择tableView或collectionView,然后从Size Inspector中的下拉列表中选择。来自'内容插入调整行为'

Size Inspector

© www.soinside.com 2019 - 2024. All rights reserved.