I have a UIScrollView which contains a button. When the button is pressed, I would like to scroll to the bottom of the view using scrollRectToVisible.
eg:
CGRect r = CGRectMake(0, myUIScrollView.contentSize.height - 1, 1, 1);
[myUIScrollView scrollRectToVisible:r animated:YES];
If I set animated to NO, everything works as expected, but if I set it to YES, I see really weird behaviour:
I've printed _geScroll_Settings.contentSize, and it's as-expected.
I've also tried to delay the call to scrollRectToVisible by starting a timer, but the results are pretty much the same.
The scrollView is fairly vanilla. I'm creating it in interface builder. I am dynamically adding the scrollView's content at startup, and adjusting it's contentSize appropriately, but all that seems to be working fine.
Any thoughts?
My bet is that scrollRectToVisible is crapping out because the visible area is not valid (1x1), or the y offset is just outside the bounds, have you tried setting it with the size of the visible area of the scrollView instead?
CGRect rectBottom = CGRectZero;
rectBottom.size = myUIScrollView.frame.size;
rectBottom.origin.y = myUIScrollView.contentSize.height - rectBottom.size.height;
rectBottom.origin.x = 0;
[myUIScrollView scrollRectToVisible:rectBottom animated:YES];
Sorry I can't help you out more, but I'm not on my Mac right now, so I can't run a test. The code above would create a CGRect of the exact size of what fits inside the scrollView visible portion, and the offset would be the last visible portion in it.
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