Search code examples
iosios11iphone-x

iOS 11. UIScrollView in IPhone X shifts when trying to change the orientation of the interface


I have two UIViewController. The first controller is used only in portrait orientation, and it contains the UIScrollView. The second controller is used only in the landscape orientation. When I try to open the second screen from the first one, the UIScrollView content is shifted to -44 by X on the first controller. This behavior exists only for the iPhone X. Does anyone know why this happens?


Solution

  • For Swift developers:

     if #available(iOS 11.0, *) {
                scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
            } else {
                // Fallback on earlier versions
            }
    }
    

    You don't need to handle this method if iOS is smaller than 11, anyway iPhone X starts with iOS 11.