'automaticallyAdjustsScrollViewInsets' was deprecated in iOS 11.0

IosSwiftXcodeDeprecated

Ios Problem Overview


I just started compiling up to iOS 11 and noticed that Apple now declared the property

var automaticallyAdjustsScrollViewInsets: Bool { get set }

as being deprecated:

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

enter image description here

Is there another property to fix this warning in iOS 11?

Will the default value stay true or how will this be handled in future?

Ios Solutions


Solution 1 - Ios

This code may help:

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

Solution 2 - Ios

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

Solution 3 - Ios

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

Solution 4 - Ios

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

self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLepidopteronView Question on Stackoverflow
Solution 1 - IostangkunyinView Answer on Stackoverflow
Solution 2 - IostotiDevView Answer on Stackoverflow
Solution 3 - IosRichard HopeView Answer on Stackoverflow
Solution 4 - IosEli017View Answer on Stackoverflow