Edward Lim Edward Lim - 29 days ago 5
iOS Question

Xcode Scroll View Auto Layout Issue when Embedding with Navigation Controller?

I seem to be having issues when it comes to embedding a scrollview within a navigation controller. So here are the steps I take, and its really easy to replicate the weird error i seem to be getting.

1.) Drag and drop a UIViewController

2.) Followed by a UIScrollView


  • add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins.



3.) Drag and drop another View into UIScrollView


  • add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins.

  • Control drag from view into scroll view, make same width and height



After the following steps you will see in the following images that the view is not following the constraints I set, for some reason it thinks 0 is +64 from the top of scroll view? Not sure what I'm doing wrong here as it is very annoying visually.

enter image description here

enter image description here

Answer

In your view controller's attributes inspector, look for the Adjust Scroll View Insets and Extend Edges Under [Top|Bottom] Bar options. enter image description here

Comments