Search code examples
iosuiscrollviewuinavigationcontrolleruinavigationbar

IOS9: UIScrollView offset in UINavigationController


This is beyond frustrating. I'm having an issue with the UINavigationController (and thus UINavigationBar) pushing my UIScrollView's content down at the top, similar to the issues found here:

iOS 7 -- navigationController is setting the contentInset and ContentOffset of my UIScrollView

IOS7 : UIScrollView offset in UINavigationController

I tried both the recommended solutions of either setting self.automaticallyAdjustsScrollViewInsets = true in my view controller's viewDidLoad() method and deselecting Adjust Scroll View Insets in the Interface Builder. Both solutions remove the margin at the top, but as a few others have noted, I can't scroll anymore.

The UIScrollView and ContentView fill the entire view controller. My content view (inside the UIScrollView) contains labels, segments, and a UITextView at the bottom. Does it have something to do with the content in Content View?

I can attach pictures if needed. Using XCode 7, Swift 2, and iOS 9.


Solution

  • I solved my issue. In auto layout, I wasn't setting my content view's height constraint. Previously, I had pinned the bottom of the content view to the view controller that contained the UIScrollView. I removed that pin and explicitly set the height. It works now.