CarouselCollectionController
open class CarouselCollectionController<T> : BaseCollectionController<T>
A subclass of BaseCollectionController
that serves as a base class that handles carousel behavior for a CollectionViewController
.
This CollectionController
subclass manages a carousel-like content layout with a page control.
The page control receives events to navigate through the content.
By default, this uses CarouselItemCell
for its cells.
The associated type can conform to the CarouselItemCellPresentable
to be able to configure the cells to present content of the type.
When subclassed, the registerComponents
and collectionView(collectionView:cellForItemAt:)
can be overriden to bypass usage of the CarouselItemCell
.
The typical usage of this class when subclassed is:
- Optionally override
registerComponents
to register cells and reusable views. - Override
loadContent(completion:)
to fetch and update content. - Optionally override
collectionView(collectionView:cellForItemAt:)
for configuring cells. Override
collectionView(collectionView:didSelectItemtAt:)
for cell select actions.
Note
Due to what maybe seems to be a bug with the Swift, methods not initially in the superclass and implemented in the subclass may not be executed. To get around this, the method needs to have an @objc
attribue.
-
Declaration
Swift
override open var collectionViewLayout: UICollectionViewLayout { get }
-
The page control for the carousel.
Declaration
Swift
open var pageControl: UIPageControl { get set }
-
Declaration
Swift
override open func setupCollectionView()
-
Declaration
Swift
override open func registerComponents()
-
Sets up the page control for the carousel.
The page control is added as as a subview of the collection view’s container and configured to scroll the collection view depending on the page control’s
currentPage
value.Declaration
Swift
open func setupPageControl()
-
Updates the collection view and collection data provider with the given items.
This updates the collectionview and collection data provider with the following steps:
- If
newItems
is empty, do nothing. - Remove all items
- Add new items to the data provider.
- Reload the collection view.
- Set the number of pages of the page control to the number of items in the data provider.
- Set the current page of the page control to 0.
Declaration
Swift
open func updateCollection(with newItems: [T])
Parameters
newItems
The new items to add to the collection view and collection data provider.
- If
-
Undocumented
Declaration
Swift
@objc open func pageControlValueChanged(_ sender: UIPageControl)
-
Undocumented
Declaration
Swift
override open func numberOfSections(in collectionView: UICollectionView) -> Int
-
Undocumented
Declaration
Swift
override open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
-
Undocumented
Declaration
Swift
override open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
-
Undocumented
Declaration
Swift
@objc open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
-
Undocumented
Declaration
Swift
@objc open func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView)