0
votes

I have a view controller with a scrollview.

The scrollview has a sub View (content view) which is a view I have copied from another VC. I cannot get the scroll to work, I have tried:

  • Set constraints of scrollview against the container (pinned top/bottom/sides =0)
  • Setting Horziontal and vertical spacing of Content view against the scrollview which also didn't work
  • Set the content view to superview Leading/Trailing space to container margin, Top space to top layout guide and Bottom Space to bottom layout guide - still no scroll
  • Have also tried to set the scrollview size in viewdidload :

    scrollView.scrollEnabled = true; scrollView.contentSize = contentView.frame.size;

And no scroll.

I am possibly missing something basic here but although have tried numerous tutorials on line I can't get my head around using scrollview.

View Hiearchy and VC

Pop up when dragging content view to scroll view enter image description here

2

2 Answers

1
votes

Your content view is not embedded in your scroll view.

1
votes

to Scroll UIScrollView you need following Steps

  1. pin UIScrollView with its SuperView from all four side Top, Left, Bottom, Right

  2. Add a contentView (UIView) in ScrollView and pin it with UIScrollView with 0 margin from all four sides. also add equal width constraint.

  3. add subviews to contentView make sure all view pinned with constraint from top bottom & also add Height Constraint for subviews.

no need to set any property or content size in code.