Infinity is a very powerful concept, so maybe my post title shouldn’t include this term. Anyway, I tried to create something similar to a infinite or endless paging scroll view.
The idea is very simple:
- Create a view including a standard scroll view.
- Provide an interface to load views for each page on demand.
- Cache views for pages (specify the maximum amount of cached pages).
- If user scrolls the view load (and cache) the next and previous view.
You will find the source code of this component (I named it InfinitePagingView) and a example project at our github repository.
InfinitePagingView is very straightforward. Just implement the
InfinitePagingDataSource protocol, create an instance of
InfinitePagingView and add it to your current view:
InfinitePagingView *infinitePagingView = [[InfinitePagingView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) andDataSource:self]; [self.view addSubview:infinitePagingView]; [infinitePagingView release];
-(UIView*) infinitePagingView:(InfinitePagingView*)infinitePagingView viewForPageIndex:(int)index gets called for each page and you can provide your custom view for the requested page.
comments powered by Disqus