2

I have a followed this answer Putting a UIScrollview in a viewcontroller (storyboard) to embed a scrollview in a viewcontroller (Mine is vertically instead of horizontally).

All the constrains are working except the fact that the view bounces back when it is let go. I have tried a lot of different solution, but none is working! Please help, I'm using autolayouts my main goal is to be able to show all the buttons on the screen through scrolling.

Demo for UIScrollView bounces back when let go

EDIT:

I have been trying all types of ways to increase the contentSize, but nothing happens - the scrollview won't scroll properly. I tried different codes from people with the same problem, but the bouncing won't stop. Am I doing anything wrong on my constraints? This is extremely frustrating, please help. My constraints (using autolayout) (as I said, I followed this answer Putting a UIScrollview in a viewcontroller (storyboard))

Community
  • 1
  • 1
Mate
  • 99
  • 10

2 Answers2

4

You have to increase your scrollView's contentSize to fit all of it's sub views.

Richmond Watkins
  • 1,342
  • 9
  • 17
  • Thanks for your comment. I have been trying different codes to increase my contentSize, but none of them works! Please read my edit of the question. Thank you! – Mate Jun 06 '16 at 19:59
  • 1
    What all did you try? There should be a setting in the storyboard. If not you can do it with `scrollView.contentSize = CGSize(width: self.scrollView.frame.width, height: 1000)` (the number 1000 is just a random number I chose) – Richmond Watkins Jun 06 '16 at 22:31
0

You should add subview to scrollview, then add all other views to that subview.

  • scrollView
    • contentView
      • subview_1
      • subview_2

Then add constraints between scrollView and contentView (leading, trailing, top, bottom) and contentView should have width and height constraints set properly (set width equal to scrollView width)... the content size will be calculated automatically.... just set height

tbilopavlovic
  • 1,096
  • 7
  • 13