DroidsOnRoids / SwiftCarousel

Lightweight, written natively in Swift, circular UIScrollView.
http://www.thedroidsonroids.com/blog/ios/circular-scroll-view-swiftcarousel/
MIT License
143 stars 43 forks source link

Timer to scroll infinitely #33

Open dtfiedler opened 8 years ago

dtfiedler commented 8 years ago

I would like a timer to scroll right every 5 seconds, with 3 images in the carousel view. Right now I have:

func scrollRight(){ let current = carousel.selectedIndex! let next = (current + 1) % (photos.count) carousel.selectItem(next, animated: true) }

but as you can see once it scrolls to the right twice, it then scrolls all the way back to the first index (0) and starts over. Is there a way to make it so that when it reaches the last photo, it scrolls right to the first image?

sunshinejr commented 8 years ago

Hey again @dtfiedler, I don't know if I understand you correctly. Would you be up for uploading gif that does the job wrong, and explain exactly how should it behave? It would be awesome. 🙇

ruslankmlv commented 8 years ago

I think his saying that when you have the last item selected and then selecting first item using carousel.selectItem(next, animated: true) where next is 0, carousel will scroll back to the first item through all previous items and it would be nice to scroll just like it's a next item, without going through all previous items. It does scroll in a circle when you're using gesture to scroll from last to first, so I'm trying to do the same when selecting item programmatically, is it possible?