Search code examples
iosswiftscrollview

How to changing a property value, UIScrollView.content.contentInsetAdjustmentBehavior to never from AppDelegate?


I have a project built from XCode 8.3.3 and on-line a long time. However in iOS 11, ScrollView has a new property which named contentInsetAdjustmentBehavior. This made all scrollViewd behavior weird in Navigation. So, I have to set the code below to all ViewController which inherent from ScrollView.

    if #available(iOS 11.0, *) {
        self.tableView.contentInsetAdjustmentBehavior = .never
    }

Since this project has lots of ViewController, is there a good way to set it in AppDelegate?

    UIScrollView.contentInsetAdjustmentBehavior = .never 

I tried, but XCode warning is

Result of call is unused, but produces 'UIScrollViewContentInsetAdjustmentBehavior'

Solution

  • Use appearance instance:

    if #available(iOS 11, *) {
        UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
    }