I have used UIScrollView
before, and am using it now, and never had a problem. I\'m now adding it to an old app, and while it works as expected (I can look at
You might want to check and see that the scrollView's delaysContentTouches
property is set to NO
.
If you call the method scrollRectToVisible
or setContentOffset
from a touch within a subview of your scrollView then your scrollView could be holding things up by delaying touches.
So, make sure you set the following in your scrollView.
scrollView.delaysContentTouches = NO;
You will most likely be able to move the scrollView with and without animation set to YES.
A little late to the game but I was having the same problem. Though I absolutely had my scrollview's content size set correctly - even excessively so for the height value. Even after extensive checks to validate the frames and content sizes - still wasn't working. I had to adjust the "bounds" frame height, then everything worked great.
Over a month later, and I finally figured it out. While the alternative above worked well, it has been bugging me and I had to finally figure it out. Turns out that it was somewhat of a stupid mistake.
Here's the old code in my viewDidLoad, where I set up the scrollView:
[clefScrollView setContentSize:CGSizeMake(clefScrollView.contentSize.width, clefView.frame.size.height)];
The value of a scrollView height or width can't be 0! I think this got past me because I was assuming that ScrollView sizes start out with a valid size, and I was missing the fact that one dimension was zero!
This works:
[clefScrollView setContentSize:CGSizeMake(clefView.frame.size.width, clefView.frame.size.height)];
Hope this helps someone out there. I definitely spent way too much time trying to debug this.
For me the problem was that a constraint in a subview was not explicit. Check that every constraint in your content is set, even if you are not needing it apparently for the layout.
Yeah, I have not had success with scrollRectToVisible:animated:
, but setContentOffset:animated:
always works for me. Out of curiosity, why do you not want to use setContentOffset:animated:
? It seems to be the proper solution.
The suggested solution above may still give an error if you haven't set the frame for the "clefScrollView".
If the solution above is used and still having the same problem, make sure you have initialized your scollView (in this case clefScrollView) frame prior to setting the content view.
clefScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,450)];
[clefScrollView setContentSize:CGSizeMake(clefView.frame.size.width, clefView.frame.size.height)];