PaginationUIManager
PaginationUIManager 是一个相当方便的 iOS 分页库。它还提供了自定义的 PullToRefresh 视图。
特性
- 轻松实现分页。
- 可以选择使用自定义刷新动画进行下拉刷新或基本(由 iOS 提供的默认选项)。
- 自动管理底部加载器(如果有更多数据要加载)。
安装
CocoaPods
CocoaPods 是 Cocoa 库的依赖管理器。您可以使用以下命令安装 Cocoapods:
$ sudo gem install cocoapods
如果您想在项目中集成 PaginationUIManager,请修改 Podfile
文件中的以下内容:
source 'https://github.com/Nickelfox/PaginationUIManager.git'
platform :ios, '9.0'
use_frameworks!
pod 'PaginationUIManager', '~> 0.1.0'
保存 Podfile
之后,运行以下命令
pod install
手动安装
如果您不希望使用任何依赖管理器在项目中,也可以手动安装此库。只需将以下行添加到您的 Podfile
文件中:
pod "PaginationUIManager", :git => 'https://github.com/Nickelfox/PaginationUIManager.git'
保存 Podfile 之后,运行以下命令:
pod install
使用方法
使用 PaginationUIManager 非常简单。您只需要创建一个类型为 PaginationUIManager 的变量。
fileprivate var paginationUIManager: PaginationUIManager?
初始化时,PaginationUIManager 需要UIScrollView(或其子类,例如UITableView或UICollectionView)和 pullToRefreshView 类型,例如 none(无)、basic(基本)或 custom(自定义)。自定义类型接受 UIView 实例。
self.paginationUIManager = PaginationUIManager(scrollView: self.tableView, pullToRefreshType: .basic)
还需要设置 paginationUIManager 的代理。
self.paginationUIManager?.delegate = self
初始化 PaginationUIManager 的 ViewController 必须遵循 PaginationUIManagerDelegate。
extension ViewController: PaginationUIManagerDelegate {
func refreshAll(completion: @escaping (Bool) -> Void) {
// your implementation.
}
func loadMore(completion: @escaping (Bool) -> Void) {
// your implementation.
}
}
refreshAll
方法在拖动刷新以获取新数据时触发。如果还有更多数据要加载,则触发 loadMore
方法。
对于自定义的拖动刷新动画,UIView 类必须是 PullToRefreshContentView 的子类。
setState
方法让您管理以下状态的动画。
状态是枚举 PullToRefreshViewState 中的情况。
public enum SSPullToRefreshViewState : UInt {
// state before you start dragging to refresh
case normal
// state when you've dragged enough to refresh
case ready
// state when data is getting refreshed
case loading
// state when data has finished loading
case closing
}
如果您在使用 UICollectionView
,请确保已启用分页并设置 UICollectionView
的 alwaysBounceVertical
属性为 true
。
示例
详细的示例在 Demo 目录中。
想要贡献?
- Fork 它
- 创建您的功能分支
git checkout -b my-new-feature
- 提交您的更改
git commit -am 'Add some feature'
- 推送到分支
git push origin my-new-feature
- 创建一个新的 Pull Request