Reputation: 37581
I'm programmatically flicking through images by having a repeating NSTimer
which when fires I set the page control's current page and the scroll view's currentOffset
.
When I get to the last image I set the page control's current page back to 0
and the scroll view's currentOffset
also back to 0
. However this has the effect of very quickly rewinding things backwards to the start rather than give the impression of going forward.
Is there a quick and easy way to do this other than use something like iCarousel?
Upvotes: 1
Views: 1096
Reputation: 77631
For any "infinite" scroll you only need it to show three items.
The previous item. The current item. The next item.
If you have an array with 5 items and you want it to scroll infinitely then you first show...
5, 1, 2 (the middle is always the current item).
If the user then swipes to view number 2 then as soon as it finishes scrolling you put number 2 into the middle like so...
1, 2, 3 and then change the offset of the view so that it is back in the middle.
i.e. you always move out and then back to the middle.
Upvotes: 1
Reputation: 9042
Not sure if this ideal for your needs but you could add the first image to the end of the UIScrollView as well.
When you hit the last image, you can set the content offset of the scroll view back to 0 (without an animation) and update your page control.
Upvotes: 0