Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top