测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
Released最后发布 | 2017年8月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由Yansong Li维护。
一个具有两级链式集合视图和花哨过渡动画的自定义视图。
import ChainPageCollectionView
// chainView is this view controller's property.
chainView = ChainPageCollectionView(viewType: .normal)
chainView.delegate = self
parentCollectionView
和childCollectionView
注册cellchainView.parentCollectionView.register(#cellType, forCellWithReuseIdentifier:#cellIdentifier)
chainView.childCollectionView.register(#cellType, forCellWithReuseIdentifier:#cellIdentifier)
ChainPageCollectionViewProtocol
func parentCollectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// return your parent data source count.
}
func parenCollectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// Dequeue and configure your parent collectionview cell
}
func childCollectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// return your child data source count.
}
func childCollectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// Dequeue and configure your child collectionview cell
}
// You will get notified by following protocol method.
func childCollectionView(_ collectionView: UICollectionView, parentCollectionViewIndex: Int) {
// When parent collection view's scroll stops, this will get called with new parent collectionview's index.
// You can use this message to fetch related child collection view's new data.
// Once you have the latest child collection view's data, set `childCollectionViewDataReady` to `true`.
// NOTE: This is important to be set, otherwise your child collection view propably will not show up again.
chainView.childCollectionViewDataReady = true
}
目前,ChainPageCollectionView
支持两种子集合视图的过渡动画类型。
public enum ChainPageChildAnimationType {
case slideOutSlideIn
case shrinkOutExpandIn
}
默认是slideOutSlideIn
,您可以在初始化阶段设置它。
let chainView = ChainPageCollectionView(viewType: .normal,
childAnimationType: #yourchoice)
您可以通过通过传递ChainPageCollectionView
指定的初始化器来自定义布局对象。
let chainView = ChainPageCollectionView(viewType: .normal,
parentColectionViewLayout: #yourlayout,
childCollectionViewLayout: #yourlayout)
您可以使用parentCollectionViewItemSize
和childCollectionViewItemSize
来设置相关布局的项目大小。
此视图的默认行为是父集合视图取此视图高度的3/4
,子集合视图取余下的部分。您可以将viewType
设置为自定义比例,类型为customParentHeight(#SomeInt, #SomeInt)
。
let chainView = ChainPageCollectionView(viewType: .customParentHeight(28, 12))
Yansong Li ( [email protected] ), wechat: jindulys_uw
可扩展的集合已在MIT许可证下发布。有关详细信息,请参阅LICENSE。