Swift Storyboard - Scrollview larger than device screen won't scroll

Viewed 27

I've tried finding a solution already on here but nothing is working for me. I'm creating a scrollview in swift storyboard (with latest version of swift and xcode) but it won't scroll.

Below is what I usually do and it always works, but normally I haven't created a view controller with content height > screen device height.

Could anyone tell me what I'm doing wrong?

(Please note the root view controller is embedded in a navigation controller, so the view controller I'm talking about below has a nav bar)

  1. I select iphone SE 3rd gen as the simulator in storyboard. I change the "simulated size" of the view controller from fixed to freeform with width:375 and height: 1750 (i.e. width = actual screen size but I want the height to be 1750 instead of the actual height 667).

  2. I add a scrollview with constraints as follows:

    - leading = 0 to safe area
    - trailing = 0 to safe area
    - top = 0 to safe area
    - bottom = 0 to safe area
    

(Note when I click the safe area the width = 375 and height = 1706)

  1. Inside the scrollview I add a view called "contentView" with constraints as follows:

    - leading = 0 to scrollview
    - trailing = 0 to scrollview
    - top = 0 to scrollview
    - bottom = 0 to scrollview
    - height = 1706 (this was the height automatically calculated in the constraints section, presume it's taking account of the nav bar which is why it's not the full 1750?)
    
  2. I set the scrollview and contentView to have equal widths and equal heights

  3. I add objects for the content inside the contentView as normal with constraints etc

Should I be updating something in particular to account for the fact that my content is taller than the screen size?

Thanks!

1 Answers

as per the answer from DonMag above, the contentView should not be the same height as the scrollview

Related