ImageFeedCollectionViewController 3.0.1

ImageFeedCollectionViewController 3.0.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期上次发布2018年3月
SwiftSwift版本4.0
SPM支持SPM

Oliver ONeill维护。



 
依赖项
OOPhotoBrowser= 2.0.10
FeedCollectionViewController= 3.0.1
 

  • Oliver ONeill

FeedCollectionViewController

Build Status
Version
License
Platform

用于创建数据流的简单界面,以便在用户滚动时动态加载数据。这受到在Facebook或Instagram上滚动照片的启发。
从使用颜色代替真实内容的示例项目中获取的图片。
FeedCollectionViewController是一个用于设置简单数据流的通用界面,而ImageFeedCollectionViewController是专门为图像设置的。ImageFeedCollectionViewController使用OOPhotoBrowser的分支,因此点击图像可以无限滚动照片。

Refresh Content by swiping down Images load as you scroll Load bulk content when the user reaches the bottom of the feed Scroll through photos one at a time by tapping them

示例

要运行示例项目,请克隆仓库,然后首先从Example目录运行pod install
示例项目演示了其功能,而不使用任何实际内容,它创建了彩色图像来显示其处理大量内容的使用。
安装
FeedCollectionViewController通过CocoaPods可用。要安装FeedCollectionViewController,只需将以下行添加到您的Podfile中。
要安装ImageFeedCollectionViewController,只需将以下行添加到您的Podfile中。

使用

设置与UICollectionViewController非常类似,您必须指定一个重用标识符和一个应该从实现的CellData中获取数据的UICollectionViewCell
ImageFeedCollectionViewController
您必须有一个自定义的ImageCellData实现,它继承自IDMPhoto,它将在图库中用作。要在使用图像URL时使用,请在ImageCellData内部使用super.init(url: imageUrl)

要自定义ImageFeedCollectionViewController中的视图,您必须实现SingleImageView并重写相关方法。相关方法是IDMCaptionView中的相同方法。

要接收显示照片变更时的更新,重写didShowPhoto(cell:ImageCellData)
要接收来自图库的图片下载失败的更新,可以重写imageFailed(cell:ImageCellData)

pod "FeedCollectionViewController"

要自定义图库工具栏,您可以重写setupToolbar(toolbar:UIToolbar, cell:ImageCellData)并根据需要做出修改。
安装

pod "ImageFeedCollectionViewController"

FeedCollectionViewController通过CocoaPods可用。要安装FeedCollectionViewController,只需将以下行添加到您的Podfile中。

要安装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

除了获取失败之外,还支持自定义错误信息和视图
通过 getErrorMessageshowErrorText 实现。

测试

测试是通过 FBSnapshotTestCase 进行的,测试结果文件包含在
Example/Tests/ReferenceImages_64/FeedCollectionViewController_Tests.Tests中。
这些是在 iPhone SE 模拟器上运行的,但是您可以通过在 setUp() 中启用 recordMode 并关闭它来在自己的设备上重新运行测试

待办事项

  • 更好的测试。目前我只实现了快照测试
  • 快照测试基于计时器,如果使用类似
    EarlGrey 将更加合适,但在尝试这样做时,我遇到了超时错误

作者

Oliver O'Neill

许可证

FeedCollectionViewController 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。