ramnik
ramnik

Reputation: 417

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:

https://github.com/Shanakor/ScrollViewIssue

Thanks in advance

Upvotes: 0

Views: 246

Answers (2)

Devran Cosmo Uenal
Devran Cosmo Uenal

Reputation: 6195

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

Uncheck Adjust Scroll View Insets


Explanation:

Since iOS 7, Apple has change 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.

Upvotes: 2

Ahmad F
Ahmad F

Reputation: 31655

Set automaticallyAdjustsScrollViewInsets to false in viewDidLoad():

override func viewDidLoad() {
    super.viewDidLoad()

    automaticallyAdjustsScrollViewInsets = false

    // Do any additional setup after loading the view, typically from a nib.
}

For more Information, check Apple's documentation.

Hope this helped.

Upvotes: 2

Related Questions