ChainPageCollectionView 1.0.6

ChainPageCollectionView 1.0.6

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Released最后发布2017年8月
SwiftSwift 版本3.0
SPM支持 SPM

Yansong Li维护。



  • 作者:
  • jindulys

ChainPageCollectionView

一个具有两级链式集合视图和花哨过渡动画的自定义视图。

演示

Demo Demo

需求

  • iOS 9.0+
  • Xcode 8

使用说明

基本用法

import ChainPageCollectionView
  1. 创建ChainPageCollectionView
// chainView is this view controller's property.
chainView = ChainPageCollectionView(viewType: .normal)
chainView.delegate = self
  1. parentCollectionViewchildCollectionView注册cell
chainView.parentCollectionView.register(#cellType, forCellWithReuseIdentifier:#cellIdentifier)
chainView.childCollectionView.register(#cellType, forCellWithReuseIdentifier:#cellIdentifier)
  1. 实现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
}
  1. 当父索引改变时更新子集合视图的数据源。
// 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)

项目大小

您可以使用parentCollectionViewItemSizechildCollectionViewItemSize来设置相关布局的项目大小。

屏幕比例

此视图的默认行为是父集合视图取此视图高度的3/4,子集合视图取余下的部分。您可以将viewType设置为自定义比例,类型为customParentHeight(#SomeInt, #SomeInt)

let chainView = ChainPageCollectionView(viewType: .customParentHeight(28, 12))

作者

Yansong Li ( [email protected] ), wechat: jindulys_uw

许可证

可扩展的集合已在MIT许可证下发布。有关详细信息,请参阅LICENSE