Shanakor Shanakor - 1 year ago 68
Swift Question

How to prevent UIScrollView from getting pushed down, when the scene is embedded in a NavigationController?

I have a rather complex setup of custom views. A StackView inside a ScrollView etc.

Everything works fine until I embed my ViewController inside a NavigationController. (took me way too long to figure that out.. grinch)

How it should look like:
Wanted result (without NavigationController)

How it looks like with NavigationController
enter image description here

I think that this has something to do with the NavigationBar. However as I am fairly new to iOS developing I can not figure out what to change.

If you want to take a look, I have created a GitHub repo under:

Thanks in advance

Answer Source

Uncheck "Adjust Scroll View Insets" in your ViewController. That fixes your problem.

Uncheck Adjust Scroll View Insets


In iOS 7, Apple changed how ViewControllers with UIScrollViews are displayed.

When the first subview of a ViewController is a UIScrollView, the UIScrollView it will be rendered beginning from the top of the ViewController - even if a UINavigationBar is on top -- unless you uncheck that button or set automaticallyAdjustsScrollViewInsets to false programmatically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download