0
votes

I am trying to make a scrollable stack view inside a scrollview but it doesn't work.

I have built a structure like this: Structure Image

If you can't see the image, this is the structure:
UIScrollView constrained to superview in all 4 directions
UIStackView (constrained to scrollview in all 4 directions + equal width)
Image Collection View (not constrained)
UIStackView (not constrained)
Stack of Labels (not constrained)

It doesn't scroll, can anyone see what I am missing?

1
Try fixing a dummy height/width for Image Collection View using constraints to see if thats the issue. - Cerlin
Hi Berlin Boss! I tried it and some weird behavior appeared. The view was like flickering but it didn't scroll. - CoderOgden
If possible, create a new project, move this design into that, bundle it, upload and share us the link. - Cerlin
Good idea! Thanks, will hopefully not get back with more trouble ;) - CoderOgden

1 Answers

8
votes

You should set ContentView in your ScrollView with constraints like:

ScrollView's Constraints:

  • Leading to superView
  • Trailing to superView
  • Top to superView
  • Bottom to superView

    These constraint's constants are 0

ContentView's Constraints:

  • Leading to superView
  • Trailing to superView
  • Top to superView
  • Bottom to superView

  • Equal height to ViewController's View (which is in the top of the view hierarchy)

  • Equal width to ViewController's View 

    Note: You should set ContentView's height constraint's priority to 700 etc. (lower than default high value)

ScrollView and ContentView's view hierarchy and constraints

Attention:

Your stackViews and collectionView must have height for scrollable.

I hope it is works.

Enjoy.