I have a UIScrollView
which contains many UIImageView
s, UILabels, etc... the labels are much longer that the UIScrollView
, but when I run the app, I cannot click and scroll down...
Why might this be?
Thanks
I have a UIScrollView
which contains many UIImageView
s, UILabels, etc... the labels are much longer that the UIScrollView
, but when I run the app, I cannot click and scroll down...
Why might this be?
Thanks
The answer above is correct - to make scrolling happen, it's necessary to set the content size.
If you're using interface builder a neat way to do this is with user defined runtime attributes. Eg:
Alot of the time the code is correct if you have followed a tutorial but what many beginners do not know is that the scrollView is NOT going to scroll normally through the simulator. It is suppose to scroll only when you press down on the mousepad and simultaneously scroll. Many Experienced XCode/Swift/Obj-C users are so use to doing this and so they do not know how it could possibly be overlooked by beginners. Ciao :-)
This code will work perfectly fine as long as you do what I said up above
I had the same issue in IB.
After setting the leading, trailing, top and bottom of the scrollView to its superView. I made the following changes to make the containerView scrollable, which worked.
To make the scrollView only scroll on horizontal direction make the constraint with scrollView's centerY = ContainerView's centerY
and to make it vertically scrollable make the scrollView's centerX = ContainerView's centerX
In my case I had to set
delaysContentTouches
to true because the objects inside the scrollView were all capturing the touch events and handling themselves rather than letting the scrollView itself handle it.If your
scrollView
is a subview of acontainerView
of some type, then make sure that yourscrollView
is within the frame or bounds of thecontainerView
. I hadcontainerView.clipsToBounds = NO
which still allowed me see the scrollView, but becausescrollView
wasn't within the bounds ofcontainerView
it wouldn't detect touch events.For example:
You will be able to see the scrollView but it won't receive user interactions.
Set
contentSize
property ofUIScrollview
inViewDidLayoutSubviews
method. Something like this