CardFlipsLayout
预览
一个简单的卡片翻转动画库。基于UICollectionView,UICollectionViewCell。使用UIViewPropertyAnimator:实现高级动画。
示例
包含示例iOS应用。
要运行示例项目,请克隆仓库,然后首先从示例目录运行 pod install
。
要求
iOS 10及以后版本。(iPhone)
Swift 4.2
安装
CocoaPods
CardFlipsLayout 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile
pod 'CardFlipsLayout'
Carthage
目前不可用。
使用方法
步骤 1.
@IBOutlet weak var overviewView: UICollectionView!
关注 dataSource 和 delegate。
步骤 2.
fileprivate var items: [Items] {
let p1 = Items(name: "name1", image: "photo1", description: "Description Text.")
let p2 = Items(name: "name2", image: "photo1", description: "Description Text.")
let p3 = Items(name: "name3", image: "photo1", description: "Description Text.")
return [p1, p2, p3, p2, p1, p3]
}
步骤 3.
override func viewDidLoad() {
super.viewDidLoad()
overviewView.collectionViewLayout = FlowLayout(itemSize: CollectionViewCell.cellSize);
overviewView.decelerationRate = UIScrollViewDecelerationRateFast
let bundle = Bundle(for: CollectionViewCell.self)
let nib = UINib(nibName: "CollectionViewCell", bundle: bundle)
overviewView.register(nib, forCellWithReuseIdentifier:CollectionViewCell.identifier)
}
步骤 4.
func overviewView(_ overviewView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let selectedCell = overviewView.cellForItem(at: indexPath)! as! CollectionViewCell
selectedCell.toggle()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//Require
let cell = overviewView.dequeueReusableCell(withReuseIdentifier: CollectionViewCell.identifier, for: indexPath) as! CollectionViewCell
cell.configure(with: items[indexPath.item], collectionView: overviewView, index: indexPath.row)
//Custom
cell.setCornerRadius(radius: 6)
cell.setCloseImage(with: "p_error") //default: non, but button's title is "⊠".
cell.setAnimationType(type: .springs_Ani) // default: .normal_Ani
return cell
}
作者
der1598c
许可证
CardFlipsLayout 基于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。