Search code examples
iosxcodecocoa-touchuiscrollviewautolayout

Autolayout with UIScrollView


I am using autolayout in Xcode and am creating a fairly tall (1300px) ViewController with a uiscrollview to navigate up and down. I made the viewcontroller freeform so its dimensions are [375,1300]. I then incorporated the scrollview, added the content view as well as all the subviews & constrained everything, leaving no constraint errors. At runtime there are no errors, but everything is all smushed into the normal screen size when I intended for it to be very tall (~1300px) and scrollable. Any clue as to what I am doing wrong?

Below is a diagram showing the issue where:

  1. The Outer Black Blox is the ViewController's view

  2. The Inner Black Boxes are subviews

  3. and The Blue Box is what is displayed on the screen

picture describing my question


Solution

  • Yes, your correct @Ryan Cocuzzo. I think you need to set sub view priority from 1000 to 250. See below screen shots.

    1) Select height constraint of the subview

    2)Then go to show to size inspector

    enter image description here

    3) Now change the priority constraint from 1000 to 250.

    enter image description here

    4)Finally you get like this

    enter image description here