Iphone – Problem with uiscrollview setcontentoffset animated not scrolling when animated:yes is set

animatediphoneuiscrollview

This is very odd and I'm wondering if anyone has any thoughts?

I'm trying to scroll a UIScrollView in response to a button press on the iPad.

If I do:

CGPoint currentOff = scrollView.contentOffset;
currentOff.x+=240;
[scrollView setContentOffset:currentOff animated: NO];

The scroll view jumps to the required position as expected, but I want it to scroll. However, when I do:

CGPoint currentOff = scrollView.contentOffset;
currentOff.x+=240;
[scrollView setContentOffset:currentOff animated: YES];

Then it doesn't do anything! I have another scroll view which is working properly and responds to setContentOffset:YES as expected, so I am quite puzzled. Any ideas on why scrolling might not happen are most welcome!

Also, - (void)scrollViewDidScroll:(UIScrollView *)sender is not receiving anything at all when animated:YES is used but is invoked when animated:NO is used!

Best Answer

I had this happen too and ended up doing this workaround:

[UIView animateWithDuration:.25 animations:^{
    self.scrollView.contentOffset = ...;
}];
Related Topic