0

I'm currently making a drawing application in Swift, but I wanted the page to be able to expand if the user wanted more room. I figured that I would use a UIScrollView to scroll around the canvas, but I wanted it to expand whenever the user went to the edge of the page, and for the UIImageView that I am drawing on to expand with it. Does anyone know how I would go about doing this? Thanks!

Micah
  • 31
  • 2

1 Answers1

0

In storyboard, drag a UIView into your UIScrollView then constrain that view to all sides of the scroll view. Then set the width to whichever value you would like (I would recommend to control drag from your view to the root view of the view controller and select equal widths), then give it a height constraint. Next, you need to connect an IBOutlet to your view controller code for the height constraint you set on the content view inside the scroll view. When you need to extend the page, add to the value of the height constraint and call layoutIfNeeded() on the scroll view.

Adam H.
  • 681
  • 3
  • 8
  • Thanks for the response! How would I go about extending it though? – Micah May 22 '16 at 19:40
  • It's in the last part of the answer. Whatever you set for the height constraint of the view inside the scroll view is the amount the user will be able to see. If that amount is greater than the height of the scroll view, then the scroll view will be able to scroll. If you want to do it when the user scrolls to the bottom, then make your view controller the delegate of the scroll view and when the user scrolls to the bottom, add to the height constraint and call `layoutIfNeeded()` on the scroll view. Need to know when the user is at the bottom? See http://stackoverflow.com/q/6217900/6361557 – Adam H. May 22 '16 at 20:43