2
votes

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.

3
I solved my issue. In auto layout, I wasn't setting my content view's height constraint. I 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.Patrick Kelly

3 Answers

2
votes

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.

1
votes

I just ran into the same issue. I had an "About" view with a bunch of labels containing static text. I had a UIScrollView inside of a view controller and it was being pushed down. I had a label pinned to the bottom of the screen that was being drawn off page when it was not necessary to do that.

I had the following view hierarchy:

  • View Controller
    • View
    • Scroll View
      • Content View (UIView)
      • Label
      • Label

Content View was pinned to the bounds of Scroll View, but the width and height had equal constraints to View.

I resolved this by adding another UIView as a child of View. My hierarchy looks like this now:

  • View Controller
    • View
    • Inner View (UIView)
    • Scroll View
      • Content View (UIView)
      • Label
      • Label

I set the height constraint on Content View to be equal height to Inner View. This resolved the issue for me and everything started displaying correctly. Inner View is pinned to the borders of View.

NOTE: In the hierarchies, the Labels should be children of Content View. In the preview, it's showing that the Markdown lists can't go that deep.

0
votes

May or may not apply to you, but if you have a Nav controller and you don't need it to be translucent you can do something along the lines self.navigationController.navigationBar.translucent = NO;

This may help with your odd offsets.