测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可 | BSD |
发布最新发布 | 2017年2月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✓ |
由 Benoit BRIATTE 维护。
PaginableBehavior
是对一个 UICollectionViewDelegateFlowLayout
的部分实现,它允许您通过几行代码轻松分页您的数据集。
以下说明将帮助您在本地机器上安装副本并运行以便开发和测试。有关在实时系统上部署项目的说明,请参阅部署。
支持 iOS 8+,已在 Xcode 8.2 上进行测试
要使用 cocoapods 安装 DGCollectionViewPaginableBehavior
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
target 'YourTarget' do
frameworks
use_frameworks!
# Pods for YourTarget
pod 'DGCollectionViewPaginableBehavior'
end
pod install
命令安装依赖。初始化你的行为
let behavior = DGCollectionViewPaginableBehavior()
您可以通过启用一些选项来自定义组件
var options = DGCollectionViewPaginableBehavior.Options(automaticFetch: false)
options.countPerPage = 20 // default value used for all section, avoiding to implement the delegate
options.animatedUpdates = true // defines if the method reloadSections will be used after fetching the data
behavior.options = options
为了与 PaginableBehavior 通信,设置其 代理
。然后将行为作为代理置于您的 CollectionView
上。
behavior.delegate = self
self.collectionView.delegate = behavior
由于 DGCollectionViewPaginableBehavior
继承自 UICollectionViewDelegateFlowLayout
,您可以实现 UICollectionViewDelegate
的方法以响应用户与 collectionView
的交互。实现 UICollectionViewDelegateFlowLayout
用于尺寸信息,最后是 DGCollectionViewPaginableBehavior
的分页行为。
/**
* Gives the number of items to fetch for a given section.
*/
@objc optional func paginableBehavior(_ paginableBehavior: DGCollectionViewPaginableBehavior, countPerPageInSection section: Int) -> Int
/**
* Core methods that will be called every time the user reach the end of the collection. Depending on the mode set for automatic fetch.
*/
@objc optional func paginableBehavior(_ paginableBehavior: DGCollectionViewPaginableBehavior, fetchDataFrom indexPath: IndexPath, count: Int, completion: @escaping (Error?, Int) -> Void)
你可能想使用自定义布局。如果是这样,请扩展 Paginable 组件的行为。下面是一个使用我们自定义布局的示例:DGCollectionViewGridLayout
/**
Since the Paginable behavior is a partial implementation of UICollecitonViewDelegate,
It's the direct instance interacting with the collection View.
If your custom layout needs a delegate with specific methods, just extend the behavior of the Paginable component.
**/
extension DGCollectionViewPaginableBehavior: DGCollectionGridLayoutDelegate {
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: DGCollectionViewGridLayout, heightForItemAt indexPath: IndexPath, columnWidth: CGFloat) -> CGFloat {
return 90
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: DGCollectionViewGridLayout, heightForHeaderIn section: Int) -> CGFloat {
return 42
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: DGCollectionViewGridLayout, heightForFooterIn section: Int) -> CGFloat {
return 90
}
}
Fastlane Fastlane 是 iOS、Mac 和 Android 开发者自动化繁琐任务的工具,例如生成截图、处理配置文件和发布你的应用。
更多详细信息请参阅 CONTRIBUTING.md!
本项目遵守 贡献者公约行为准则。通过参与,你应遵守此准则。如有不适当的行为,请向 [email protected] 报告。
DGCollectionViewPaginableBehavior 是在 BSD 3-Clause 许可协议 下发布的。