Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView in Storyboard not working with iOS 8 Size Classes and Autolayout

Tags:

So I'm trying to create a UIScrollView only in storyboard that allows me to add scrolling labels for more than the height of the VC. Here's what I did:

  1. Created UIScrollView that took up the size of the any width any height VC

  2. Made constraints 0 for spacing to nearest neighbor on top, bottom, left, and right

  3. Created a view that is a subView of the UIScrollView with the same width as the any width any height VC but height of 1500 (because I only want it to scroll vertically).

  4. Set constraints to nearest neighbor as 0 for ONLY left, top, and right and set the height constraint as 1500.

  5. I put a label at the top of the subView and at the bottom

When I run the app on an iPhone 6, does not scroll vertically as I want it to. Any ideas why this is not working? Thanks in advance.

like image 701
Lucas Avatar asked Nov 04 '14 18:11

Lucas


1 Answers

To obtain the scroll you have to pin the sub view (the "content view") to the top, left, bottom and right of the scrollview. In addition you have to give it (to the "content view") an explicit (=not related to the scroll view) height and width because these are used by the scrollview to calculate its content size. In your case set the width equal to the VC main view width and the height to 1500. When width or height are bigger than the scrollview size, it will scroll.

Scroll view constraints (pinned to main view)

scroll view constraints

Content view (pinned to scrollview + height 1500, width=mainview width) + label constraints (as an example: 20 20 from content view top left)

content view + label constraints

like image 166
valfer Avatar answered Sep 20 '22 13:09

valfer