views:

1347

answers:

3

Hi,

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

A: 

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?

St3fan
you can make it "endless" by shuffling around its subviews and keep on resetting the content offset, it works.
bibac
You obviously didn't read the question, and haven't contributed anything.
David M.
+1  A: 

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

bibac
A: 

I landed on this page, because I'm seeing a strangeness where no drawing occurs in the content view of a UIScrollView if the UIScollView.contentSize.width is greater than 10K (10K works, 20K doesn't draw, despite drawRect: being called just fine)

if I clip the contentSize.width to 10K, drawing never fails.

so, the snarky CGFLOAT_MAX (340282346638528859811704183484516925440) doesn't seem appropriate

(before someone says 10K is too big, there are extenuating circumstances, and I have other navigational UI than just swipe gesture)

pixeled