Reputation: 40765
I have like 20 items which the user can pick from. Now I want to make a UIScrollView with enabled pagination, that allows to scroll for ever. If the end is reached, the start is appended, and so on.
What would be the simplest way to do something like this? I fear that when I reach an offset of lets say y=10000.0f, it may affect memory. Not sure.
Also a smooth "forever scrolling experience" is important. So just setting the offset to 0/0 when the end is reached will most likely not work... I remember I tried that a year ago, and the UIScrollView animated the whole thing backwards (wrong direction, from end to start) when the offset was set to something else.
Upvotes: 1
Views: 726
Reputation: 33602
A large offset does not consume extra memory; it just requires that CoreAnimation deals with large numbers. This is fine, except...
CGFloat is a float on device (IIRC it's a double on Mac OS X). This means it can represent integers up to about 224 (about 16.7 million), thus half-integers up to around 8 million (and the "retina display" has half-size pixels). If the user scrolls very far, then you'll lose accuracy. I'm not sure where precisely this happens. You can try setting contentSize and contentOffset to very large values and seeing what happens.
If you really need UIDatePicker-style "forever" scrolling, you have a few options:
scrollViewDidEndDragging:willDecelerate:
(but only if decelerate == NO
)scrollViewDidEndDecelerating:
scrollViewDidEndScrollingAnimation:
scrollViewDidScrollToTop:
(possibly; I'm not sure if it sends scrollViewDidEndScrollingAnimation: too).This means the user can hit the end and bounce if they try really hard (a million iPhone "points" is about 160 m). Oh well.
Upvotes: 3