I'm attempting to implement a collection view with an infinite scrolling behaviour. The scrolling should be circular - like in a UIPickerView
. Can it be done with Apple's UICollectionView
or there is no choice but to create a horizontal PickerView ?
What do you think?
Thanks to rdelmar for a tricky solution. That idea of "large number for collectionView:numberOfItemsInSection" worked like a charm. I have tried to implement the same with UIScrollView delegate methods. But the output was jerky.
Here's some part of my code.
// CellforRow
}
// DidSelect
}
This will give infinite scrolling effect. To enable infinite scrolling both sides, use ScrolltoIndexpath:(middle of Itemscount) in ViewWillAppear !! Hope this will help someone who are about to build an infinite scrolling UICollectionView.
Override this method to enable infinite scrolling both ways. It center content whenever it is too far from the center and user never hits the end.
Yes, you can do this. Return a very large number for collectionView:numberOfItemsInSection:, and in collectionView:cellForItemAtIndexPath:, you use the mod operator to always return a number for indexPath.Row that's between 0 and the last index in your data array. So if you had 20 items in your array, you would do something like this:
You should watch the WWDC 2011 session video "Advanced ScrollView Techniques", they talk about infinite scrolling, and I'm pretty sure it's possible to use that with
UICollectionView
s. It recenters while you scroll, and places the new items after the current visible items (or before, depending on the scroll direction).Like they say in the session, you should not use an approach that has an ending. Like stated in the session: People will definitely find the edge at one point.