测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布日期上次发布 | 2018年3月 |
SwiftSwift版本 | 4.0 |
SPM支持SPM | ✗ |
由Oliver ONeill维护。
依赖项 | |
OOPhotoBrowser | = 2.0.10 |
FeedCollectionViewController | = 3.0.1 |
用于创建数据流的简单界面,以便在用户滚动时动态加载数据。这受到在Facebook或Instagram上滚动照片的启发。
从使用颜色代替真实内容的示例项目中获取的图片。
FeedCollectionViewController是一个用于设置简单数据流的通用界面,而ImageFeedCollectionViewController是专门为图像设置的。ImageFeedCollectionViewController使用OOPhotoBrowser的分支,因此点击图像可以无限滚动照片。
示例
要运行示例项目,请克隆仓库,然后首先从Example目录运行pod install
。
示例项目演示了其功能,而不使用任何实际内容,它创建了彩色图像来显示其处理大量内容的使用。
安装
FeedCollectionViewController通过CocoaPods可用。要安装FeedCollectionViewController,只需将以下行添加到您的Podfile中。
要安装ImageFeedCollectionViewController,只需将以下行添加到您的Podfile中。
设置与UICollectionViewController
非常类似,您必须指定一个重用标识符和一个应该从实现的CellData
中获取数据的UICollectionViewCell
。
ImageFeedCollectionViewController
您必须有一个自定义的ImageCellData
实现,它继承自IDMPhoto
,它将在图库中用作。要在使用图像URL时使用,请在ImageCellData
内部使用super.init(url: imageUrl)
。
SingleImageView
并重写相关方法。相关方法是IDMCaptionView
中的相同方法。要接收显示照片变更时的更新,重写didShowPhoto(cell:ImageCellData)
要接收来自图库的图片下载失败的更新,可以重写imageFailed(cell:ImageCellData)
pod "FeedCollectionViewController"
要自定义图库工具栏,您可以重写setupToolbar(toolbar:UIToolbar, cell:ImageCellData)
并根据需要做出修改。
安装
pod "ImageFeedCollectionViewController"
要安装ImageFeedCollectionViewController,只需将以下行添加到您的Podfile中。
使用
The set up is quite similar to UICollectionViewController
, you must specify a
FeedCollectionViewController
open func getReuseIdentifier(cell:CellData) -> String {
// specifies the identifier of the cell, this can differ per cell
}
open func getCells(start:Int, callback: @escaping (([CellData]) -> Void)) {
// get new cell data, this does not actually mean the cell is being shown
// call `callback` with the new data. `start` is the query starting position
}
open func loadCell(cellView: UICollectionViewCell, cell:CellData) {
// load the cell since it's now actually shown
}
reuse identifier and a UICollectionViewCell
that should take its data from an
open func getImageReuseIdentifier(cell: ImageCellData) -> String {
// specifies the identifier of the cell, this can differ per cell
}
open func getImageCells(start:Int, callback: @escaping (([ImageCellData]) -> Void)) {
// get new cell data, this does not actually mean the cell is being shown
// call `callback` with the new data. `start` is the query starting position
}
open func loadImageCell(cellView: UICollectionViewCell, cell:ImageCellData) {
// load the cell (ie. a thumbnail) since it's now actually shown
}
implemented CellData
.
ImageFeedCollectionViewController
You must have a custom ImageCellData
implementation, this subclasses
IDMPhoto
, which will be used in the photo browser. To use with image
URLs use super.init(url: imageUrl)
within ImageCellData
.
To customise views in the ImageFeedCollectionViewController, you must
open override func setupCaption() {
// Setup caption views
}
open override func sizeThatFits(_ size: CGSize) -> CGSize {
// Return the height of the view, the width will be ignored
}
implement SingleImageView
and override relevant methods. The relevant
methods are the same as those in IDMCaptionView
.
To receive updates when the displayed photo changes, override
.didShowPhoto(cell:ImageCellData)
To receive image download failures from the photo browser, you can override
imageFailed(cell:ImageCellData)
To customise the photo browser's toolbar, you can override
除了获取失败之外,还支持自定义错误信息和视图
通过 getErrorMessage
或 showErrorText
实现。
测试是通过 FBSnapshotTestCase 进行的,测试结果文件包含在Example/Tests/ReferenceImages_64/FeedCollectionViewController_Tests.Tests
中。
这些是在 iPhone SE 模拟器上运行的,但是您可以通过在 setUp()
中启用 recordMode
并关闭它来在自己的设备上重新运行测试
。
。
Oliver O'Neill
FeedCollectionViewController 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。