0

Hello Mobile developers!

I'm creating an app and I'm not being able to make it scrollable. I've inserted a ScrollView and inside a vertical StackView with 3 Views.

I am new to swift and I'm not really sure what to provide for you to help me, se here's a couple of screenshots that may help.

Running app

View Structure

Some constraints

ScrollView details

Any other comments regarding the structure or good practices are welcome.

UPDATE: The app is now scrolling, but for some reason I'm not being able to scroll the whole way down. It seems like it's grabbing the full hight of the device as height of the scroll, even though the content I'm inserting is dynamic.

I have a video in the following link so you can have a visual reference: https://drive.google.com/file/d/1UmE9NEVTxbK_rFPJarhfohPFb8XD8HcA/view?usp=sharing

  • `scrollView.contentSize` determines the scrollable area of a `UIScrollView`. If it's not set anywhere, it will never scroll. You can set it in code (in viewDidLoad maybe). Setting it in the storyboard can be a little tricky because it depends on your view hierarchy and constraints of sub views. You can try setting the leading, trailing, top and bottom of the main stack view to the content layout guide for starters – Fourth Apr 27 '21 at 09:55
  • Your question and your layout are a bit confusing... what are you trying to scroll? Your scroll view has a **vertical stack view** (with confusing constraints on its arranged subviews)... and you mention a *horizontal stack view* ... do you want to scroll vertically when the content is taller than the scroll view? – DonMag Apr 27 '21 at 12:51
  • @DonMag sorry, I meant vertical scroll view. – Rodrigo Camargo Apr 27 '21 at 14:33

1 Answers1

1

I think the problem is that you haven't add View inside your scrollview and also uncheck "Content Layout Guides" in Size inspector section for your scrollView. That view is your main content View. So your hierarchy will be like ScrollView -> View -> and then your main Stack View. Don't forget to give your main content view any fixed height so it will work perfectly. You can also dynamically handle main content view Height constraint. You can also take a quick guide from following answer which work perfectly fine. https://stackoverflow.com/a/59047168/12969732

I hope it will helps. Let me know if you have any query.

  • Thank you so much! Now the app is scrollable. However, for some reason it is not adjusting to the height of the content. Is scrolls and bounces but only stays a few points below the starting position. I printed the height of the height of the scroll view and of the stack view, and no matter the length of the description, the heights are always 798pt for scroll view and 802pt for stack view. There's something I'm doing wrong that won't resize the "description" view dynamically depending on the content of the label. I even tried forcing a static width for the scroll view and did not work – Rodrigo Camargo Apr 27 '21 at 16:46
  • Your welcome mate! It might be the problem with your constraints. One way to solve your problem to give constraints to scrollView for top/bottom/trailing/leading to superView(1) and equal width to superView(1). And then you should define height for you main content view (that you have added inside scroll view) and also height of stack view then you should dynamically handle height constraint of main content view and stack view depending upon how long is your "description". – Osama Fahim Apr 28 '21 at 08:18