views:

149

answers:

1

Hi,

I have a UIScroll which has eight or so pages. My aim is for them to 'loop' around so that when the user reaches the last page the first page will be the next page (and vice versa) so that the user could scroll through the pages endlessly. What is the best way to achieve this?

I am working from this example from Cocoa with Love.

Any help is greatly appreciated. Thank you.

+3  A: 

Problem is sorted now. Basically, I created extra pages before and after my pages so it looks like this:

8 1 2 3 4 5 6 7 8 1

Then in the scrollViewDidEndDecelerating I do a simple if statement that checks if I am at either the first or last page and locate the scrollView appropriately.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)newScrollView
{
    [self scrollViewDidEndScrollingAnimation:newScrollView];
    pageControl.currentPage = currentPage.pageIndex;

    if(currentPage.pageIndex==0){
        scrollView.contentOffset = CGPointMake(320*(pageControl.numberOfPages-2), 0);
        pageControl.currentPage = pageControl.numberOfPages-2;
    }else if(currentPage.pageIndex==pageControl.numberOfPages-1){
        scrollView.contentOffset = CGPointMake(320, 0);
        pageControl.currentPage = 1;
    }

}
Skream