Question

I need to build a scroll view (with 10 items for example) that can be continuously scrolled (with paging enabled). In other words as you keep scrolling to the right, you see the item you started with once to get to the end, and it just keeps looping.

I'm looking for recommendations on how to a approach this. I will be receiving an array of images. I can lay them out next to each other no problem. My main concern is how/when to move the images so they keep appearing in a loop as you scroll. Thanks!

Was it helpful?

Solution

Use -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; delegate to know when someone's moving through your scroll view.

When you get to the last page you need to move the first image view in the scroll view to the end. ie:

for(UIImageView *image in myscrollview){
    if(image.frame.origin.x == 0){
        // move to the end...
    }
    else{
        // move your image a scroll view's width to the left...
    }
}

obviously it will be much more complicated than this, you will have to work out which way the user is scrolling and sort it out like that, but this gives you a basis to start with. :)

OTHER TIPS

Append the first picture as the last picture. Just as you move further right from the last picture, jump to the first.

And vice versa of course.

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