AMScrollingCards
需求
iOS 9+
安装
AMScrollingCards 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'AMScrollingCards'
描述
该 Pod 旨在提供一个分页翻页的水平卡片界面组件,具有聚焦于当前选中卡片并使用集合视图预览下一张和上一张卡片的功能,以确保可靠性并提高内存效率。
演示
用法
/*
Initialize Configuration instance of manager by passing
================================================
1. the enclosing View for the cards
2. number of cards
3. custom cell identifier
4. delegate
5. nib file of the custom cell
6. spacing between cards defaults to 10
7. if module should add a page indicator
8. page indicator colors
9. peak size which is the size of the left and right cards that should be shown
10. if the cards should use animation to focus on selected card
=================================================
*/
let config = SwipingCardsConfigurationModel(containerView: scrollingCardsContainer ,
numberOfItems: data.count,
identifier: "cardCell",
delegate: self,
cellNib: UINib.init(nibName: "CustomCollectionViewCell",bundle: nil),
spacing: 10,
usePageIndicator: false,
selectedPageDotColor: UIColor.red,
pageDotColor: UIColor.blue,
peakSize: 25,
shouldUseScaleAnimation: true)
// init module mannager
swipingCardsManager = SwipingCardsManager(config: config)
// simply show the cards
swipingCardsManager.showCards()
委托
func getCellForIndexPath(cell: UICollectionViewCell, indexPath: IndexPath) -> UICollectionViewCell {
// create cell of the nib file you passed inn the cofig
return cell
}
// To be called when a card is tapped
func didSelectCard(index: Int) {
print("Selected Card At index -> \(index)")
}
// to be called each time a card is swiped and being focused
func didChangeCard(index: Int) {
print("current index \(index)")
}
致谢
https://medium.com/@shaibalassiano/tutorial-horizontal-uicollectionview-with-paging-9421b479ee94
许可
AMScrollingCards 在MIT许可下可用。有关更多信息,请参阅LICENSE文件。