开发者

iPhone UIScrollView / setContentOffset weirdness

I have a weird issue with setContentOffset which I don't seem to be able to solve: I'm trying to build an "endless" scroll view, so I'd like to reset the content offset at a certain position. With the code below setContentOffset will be ca开发者_C百科lled at x=160px. If I drag the scroll view my log looks like this:

offset: 158

offset: 159

offset: 160

offset: 80

offset: 160

What happens is that my setContentOffset (to 80) is performed, when I keep on dragging UIScrollView seem to have forgotten about it and continues at 160. Even weirder: When I set animated:YES it works. Maybe a timing issue? When I call setContentOffset from within scrollViewDidScroll, scrollViewDidScroll will be called again.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
 NSInteger tileNo = floor(scrollView.contentOffset.x / 80);
 NSLog(@"offset: %f, tile: %d, lastTile: %d", scrollView.contentOffset.x, tileNo, lastTileNo);

 if (tileNo > lastTileNo) {
      [scrollView setContentOffset:CGPointMake(80, 0) animated:NO];
 }

 lastTileNo = tileNo;

}

Thanks for helping me out, Stephan


Just got this answer from sombody at Apple: "This is a known issue and will be fixed in a future release of the iPhone SDK. If you're able to test it, you should actually find it's fixed in the current beta. If you're still having trouble with that please file a new bug."


Same issue here.

It's some kind of inconsistency by calling setContentOffset: inside scrollViewDidScroll:, it updates the tableview's contentOffset only till the next call of scrollViewDidScroll:.

I realised that this bug only happens when the user is not dragging the tableview (only decelerating).

In my case, updating only when the user is dragging solved the problem.

Hope it helps.


The problem is that the UIScrollView is not endless by design. It has a hard limit of it's content size. Are you sure that CGFLOAT_MAX (340282346638528859811704183484516925440) is too small for your scroll view?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜