I have a UIScrollView
created in interface builder with a bunch of UITextView
and UIImageView
objects already added. I have it connected to an IBOutlet
, and under -(void)viewDidLoad
I set its content size to 1200x2000
. User interaction Enabled, Multitouch, Scrolling Enabled and shows vertical and horizontal scroll indicators are all set to YES
. When I launch the app in the iOS simulator, it doesn't scroll. What could possibly be the cause of this behavior?
viewDidLoad is to soon. You must wait until after the layout of the views has taken place. Try setting the contentSize in viewDidAppear.
Are you using autolayout? If so, check out the following answer (and forget 1.): UIScrollView doesn't use autolayout constraints.
The best way I know how to overcome this problem without resorting to writing code is that it all can be done within a storyboard and here is how:
viewDidLoad
is indeed too soon, but viewDidAppear:animated
might not be late enough either. The ideal place to set the contentOffset
is inside viewDidLayoutSubviews
.
If you're using Autolayout, make sure you put the code to set Content size within
viewDidLayoutSubviews
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With