1

So i have the following code:

int actualPosition = self.collectionView.contentOffset.y;
NSLog(@"%i", actualPosition);

The output is:

2013-03-28 15:36:42.737 test[10544:907] 484
2013-03-28 15:36:42.754 test[10544:907] 490
2013-03-28 15:36:42.770 test[10544:907] 512
2013-03-28 15:36:42.787 test[10544:907] 550

My question now is: why does it "skip" (as in why does "actualPosition" never have those values) 485-489, 491-511, and 513-549? Shouldn't it log/give actualPosition this value for all the "positions", even when I scroll faster? It works the same way for float, so this does not matter. How do I solve this so that actualPosition receives the value of every position that has been scrolled through?

schnabler
  • 687
  • 7
  • 23

1 Answers1

1

Since there are a lot of pixels in screen and only some time to move what you scrolled, those values get "jumped" over by FPS. In other words if you move 100 pixels in 1 second with 30fps, one fps will jump value by 33 pixels. So you will get +3 every step instead of +1.

Getting exact position all the time is impossible, since there may be some scroll gesture so fast, that whole screen flies by in one frame. So the "jump" would be as big as screen.

avuthless
  • 996
  • 2
  • 12
  • 27
  • that sounds very reasonable. but it also means, i won't be able to use contentOffset.y; for my infinite scrolling - right now, i do: (actualPosition == contentHeight), but it's up to the FPS gods for this condition to apply - too bad. thanks a lot for your response. – schnabler Mar 28 '13 at 15:59
  • yeah, but (actualPosition >= contentHeight) will "fire" multiple times (as in "a lot of times"), which is not what i want. – schnabler Mar 28 '13 at 16:04
  • Well you can use bool to set it as "noticed" like if(actualPosition >= contentHeight && !noticed){ noticed = true; //do stuff } This way only one call will be accepted. – avuthless Mar 28 '13 at 16:09
  • or you could just slow everything down – avuthless Mar 28 '13 at 16:16
  • the bool thing works like a charme. thanks a lot, lithuanian friend. – schnabler Mar 28 '13 at 16:35