Reputation: 417
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)
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
Reputation: 6195
Uncheck "Adjust Scroll View Insets" in your ViewController. That fixes your problem.
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
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