DTPhotoViewerController 3.1.0

DTPhotoViewerController 3.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2019年9月
SPM支持SPM

Tung Vo 维护。



  • Tung Vo

DTPhotoViewerController

Version License Platform

示例

Screenshot

演示视频:https://youtu.be/aTLx4M4zsKk

DTPhotoViewerController 非常易于使用,如果您只想在相册中显示一张图片,您只需传递 UIImageView 和 UIImage 实例即可。

if let viewController = DTPhotoViewerController(referencedView: imageView, image: image) {
    self.presentViewController(viewController, animated: true, completion: nil)
}

对于多张图片,您需要向 DTPhotoViewerController 实例提供数据源。DTPhotoViewerControllerDataSource 有三个必需的方法和一个可选的方法,以下是如何实现它们的示例,这个示例也可以在演示中找到

func photoViewerController(_ photoViewerController: DTPhotoViewerController, referencedViewForPhotoAt index: Int) -> UIView? {
    let indexPath = IndexPath(item: index, section: 0)
    if let cell = self.collectionView?.cellForItem(at: indexPath) as? CollectionViewCell {
        return cell.imageView
    }
        
    return nil
}

func numberOfItems(in photoViewerController: DTPhotoViewerController) -> Int {
    return images.count
}

func photoViewerController(_ photoViewerController: DTPhotoViewerController, configureCell cell: DTPhotoCollectionViewCell, forPhotoAt index: Int) {
     // You need to implement this method usually when using custom DTPhotoCollectionViewCell and configure each photo differently.
}
    
func photoViewerController(_ photoViewerController: DTPhotoViewerController, configurePhotoAt index: Int, withImageView imageView: UIImageView) {
    imageView.image = images[index]
}

如果您想要为每张图片添加更多 UI 元素,最佳方法是为 DTPhotoCollectionViewCell 创建一个子类,然后调用下面这些方法中的一个:registerClassPhotoViewer: 或 registerNibForPhotoViewer

if let viewController = BDFPostPhotoViewerController(referencedView: cell.imageView, image: cell.imageView.image) {
     viewController.registerClassPhotoViewer(DTCustomPhotoCollectionViewCell.self)
}

如果您想自定义 DTPhotoViewerController 的行为,还有委托 (DTPhotoViewerControllerDelegate)。

要运行示例项目,首先克隆仓库,然后从 Example 目录中运行 pod install 命令。

要求

安装

CocoaPods

DTPhotoViewerController 支持通过 CocoaPods。要安装它,只需将以下行添加到您的 Podfile 中

对于 Swift 5

pod "DTPhotoViewerController"

对于 Swift 4.2

pod 'DTPhotoViewerController', '~> 1.2.5'

Swift 包管理器

DTPhotoViewerController 从版本 3.0.2 开始支持 SPM。将以下内容添加到您的 Package.swift

.package(url: "https://github.com/tungvoduc/DTPhotoViewerController", from: "version")

作者

Tung Vo, [email protected]

许可

DTPhotoViewerController 在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。

反馈 & 请求

  • 如果您发现了一个错误,提出建议或只是需要一些帮助,请发起一个问题。
  • 您还可以通过 电子邮件联系我。