UIScrollView works as expected but scrollRectToVisible: does nothing
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.
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.
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.