UIScrollView not working – scrolling doesn’t work
Nov.18, 2008 in
Development, iPhone Development, iphone
Okay, so I’ve just spent the last few hours trying to work out why my UIScrollView won’t scroll! The secret, I’ve found, is the following:
- (void)viewDidLoad {
[super viewDidLoad];
// Setup scroll view
[scrollView
setContentSize:CGSizeMake(backgroundImage.frame.size.width,
backgroundImage.frame.size.height+200)];
}
You must call setContentSize and pass it an object which has a greater size than the ScrollView itself. Also, you need to do this after the view has loaded (so use viewDidLoad). In my example I was using a UIScrollView to allow me to scroll an image, which is a sub-view of the UIScrollView (all setup in IB).
Tags: iphone, iPhone Development

February 5th, 2009 at 7:35 am
I was just having a similar non-scrolling issue, but had failed to set contentSize properly. As far as I can tell it doesn’t have to happen in the viewDidLoad function, but can be set anytime after you create the UIScrollView. Thanks for the post.
February 13th, 2009 at 6:12 am
Thanks for this, couldn’t figure out why my UIScrollView wouldn’t scroll by default.
March 11th, 2009 at 8:47 pm
Thank you very much! I just was starting to get really pissed off.
July 8th, 2009 at 4:04 pm
Nice work on this one… but could you also tell me how to fix my application and be a good programmer?? I know its asking a lot, but some free private lessons would be great. Even better, could you pay me for it?
October 11th, 2009 at 12:21 am
Thank you SOOOO much. Have hunted everywhere for an explanation and couldnt find one until I found this. Cheers!
January 7th, 2010 at 7:27 pm
Thanks bro
code is working for me
January 28th, 2010 at 11:58 am
The mac documentation is horrible on UIScrollView. Thanks for this.
Make sure the view you are scrolling is setting its bounds accordingly! I had the case where the bounds of the content view was just the regular screen size.
March 6th, 2010 at 12:20 am
Thank you very much!!! It also works with scrollviews created in the IB and having view controller class. You must cast its view property to UIScrollView:
[(UIScrollView*)self.view setContentSize:CGSizeMake(X, Y)];
March 27th, 2010 at 1:02 am
Nice one dude — i was doing the setContentSize but your comment about ensuring the size you pass in is greater than the IB set scroll view pointed me to my real problem. Thanks v much!
April 1st, 2010 at 3:45 am
Thanks man, setContentSize was all I needed to get a simple scrollable map image in a UIScrollView. I was just about to start messing with delegates and drawRect but I saw this post and it fixed my issue. Thanks!
April 10th, 2010 at 2:56 am
Thanks! I wasted hours trying to figure this out before I saw this. Seems like the scroll view should be able to determine the content size on its own, but I guess not.
May 21st, 2010 at 11:05 pm
Thanks!
August 20th, 2010 at 3:58 am
DUDE!!!
Thanks…