My UIScrollView won\'t scroll down. I don\'t know why. I already followed Apple documentation regarding to this issue.
@IBOutlet weak var scroller: UIScrollView!
If you are using Storyboard
:
UIScrollView
top
, bottom
, left
and right
constraints with the scroll viewheights
and widths
constraintsEqual Heights Constraint
priority to 250
. For a horizontal scroll set the Equal Widths Constraint
priority to 250
You need to set the frame
of your UIScrollView
so that it is less than the contentsize
. Otherwise, it won't scroll.
Also, I would recommend that you add scroller.contentSize = CGSizeMake(400, 2300)
to your viewDidLoad
method.
Swift 3.0 version
scroller.contentSize = CGSize(width: scroller.contentSize.width, height: 2000)
In my case, I used UIStackView inside UIScrollView.
Added some views-elements from code to stackview. It won't scroll.
Fixed it by setting stackview's userInteractionEnabled
to false
.
Do not give fix height to scroll view and always give top of first subview to scrollview and bottom of last subview to scrollview. By this way scroll view will automatically grow as per the size of contained subviews. No need to give contentSize to the scrollview.It will work for small as well as large size iPhone.
If you are using autolayout, then the contentSize property stops working and it will try to infer the content size from the constraints. If that is the case, then your problem could be that you are not defining the necessary constraints to the content view so that the scrollview can infer the content size. You should define the constraints of your content view to the top and bottom edges of the scrollview.