Folio 1.0.0-beta.2

Folio 1.0.0-beta.2

Levi Bostian维护。



Folio 1.0.0-beta.2

  • 作者
  • Levi Bostian

CI Status Version License Platform Swift 5.2.x

Folio

Folio是一种灵活的方式来检测当您滚动到UITableView的末尾时。

project logo

什么是Folio?

有时,检测您滚动到UITableView末尾很有价值。一个场景是如果您的应用程序正在尝试实现分页。Folio的作用是告诉您何时已滚动到UITableView的底部。仅此而已。

为什么要使用Folio?

  • 轻量级 - Folio非常小巧。只有一个类和一些代码行。请查看
  • 与带分区的UITableView一起工作 - 一些滚动检测器只能在您的表格只有一个分区时使用。无论您有多少个分区,Folio都会告诉您何时已滚动到UITableView的末尾。它告诉您何时到达了表格的最后一个分区的末尾。
  • 灵活 - 您无需更改现有的实现。您无需使用UITableView的自定义子类。使用您想要的任何UITableView实例!
  • 易于实现 - 有两个步骤。(1) 设置代理和(2) 一个函数调用。

安装

Folio 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 中:

pod 'Folio', '~> version-here'

version-here 替换如下: 版本,因为这是当前的最新版本。

开始使用

  • 创建 Folio 的实例并在其上设置一个 delegate
import UIKit
import Folio

class ViewController: UIViewController {

    fileprivate var folio: Folio!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        folio = Folio(tableView: tableView)
        folio.delegate = self
        ...
    }
}
  • 实现 FolioDelegate
extension ViewController: FolioDelegate {

    func reachedBottom(in tableView: UITableView) {
        // Reached bottom of UITableView. 
        //
        // Note: This function is only called once until you call `tableView.reloadData()`. 
    }

    // Optional.
    func reachedTop(in tableView: UITableView) {
        // Scrolled to the top of the UITableView. 
        // 
        // Note: This function is only called once until you call `tableView.reloadData()`.         
    }
}
  • 在你的 UITableViewDelegate 中,向 Folio 传递一些信息
extension ViewController: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {        
        folio.tableView(tableView, willDisplay: cell, forRowAt: indexPath)
    }

}

如何工作?

Folio 非常简单。为了确保 Folio 不是一个黑盒,让我们深入了解 Folio 的工作原理。

它是一个短文件,(1)确定你的 UITableView 的最后一个节和最后一个行的位置,然后(2)在 UITableView 准备显示最后一个节和最后一个单元格时通知您的设置 delegate

UITableView 实例会在每个节中显示一定数量的行,而 Folio 只关心 UITableView 的最后一个节和最后一个行。

查找 Folio 的 源代码文件,里面有一些注释解释这一点。

示例应用程序

本项目包含一个 iOS 应用程序,您可以运行并查看源代码,以了解使用 Folio 实现分页的完整实现。

要运行示例应用程序,请按照以下说明操作。

cd Example/
pod install

然后,在 XCode 中打开 Folio 工作空间。

作者

Levi Bostian image

贡献

Folio 接受 pull requests。查看 问题列表 了解计划中的任务,如有意向以此方式贡献,请查看。

想向 Folio 添加功能吗? 在决定花费大量时间向库中添加功能之前,请先 创建一个问题 说明您想添加的内容。这可能有助于您判断您的要求是否适合 Folio 的用例。您当然可以创建此库的分叉并进行任何您希望进行的更改!

名字从哪里来的?

经过对“分页”的同义词进行快速搜索后,出现了“folio”。folio 被定义为以某种顺序排列纸张。这个词很有趣,与它的常见用例 -> 分页非常契合。

版权信息

头图来自 JJ Ying,在 Unsplash 上。

许可证

Folio 在 MIT 许可证下可用。更多信息请查看 LICENSE 文件。