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 called 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."
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