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

Viewed 34350

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!

9 Answers

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

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

I'm working with tableviews, as aepryus solution's says: setContentOffset: is getting called concurrently with other animations.

In my case I've just invert this commands:

[tableView reloadData];
[tableView setContentOffset:CGPointMake(240, 0) animated:FALSE];

like this

[tableView setContentOffset:CGPointMake(240, 0) animated:FALSE];
[tableView reloadData];

The animation start after the content offset has changed successfully.

Related