UIScrollView bug

This post describes a bug in UIScrollView that occurs when you programmatically set the contentOffset with animation. Below is code to reproduce the bug; I’ve confirmed it’s in iPhone OS 3.2 but it may be in other versions as well.

If you make a call to

[scrollView setContentOffset:offset1 animated:YES];

and later make a call to

scrollView.contentOffset = offset2;

before the animation is done, the scroll view will not end up at offset2, but rather somewhere else that seems to depend on the original position, offset1, and the timing of the calls.

I don’t have a good workaround for this bug. For now I’m just not animating my programmatic scrolls.

Here’s a screenshot from the reproduction of the bug:

Because of the last contentOffset setting, I would expect to see the top of the scroll content (a green bar) in the scroll area, instead of the bottom, which is what we do see.

Here is a one-class xcode project to reproduce the bug.

One Comment