DKPhotoGallery 0.0.19

DKPhotoGallery 0.0.19

Bannings 维护。



 
依赖库
SDWebImage>= 0
SwiftyGif>= 0
 

  • 作者
  • Bannings

DKPhotoGallery

Build Status Version Status Carthage compatible license MIT

特性

  • PNG|JPEG|GIF|PHAsset
  • AVPlayer
  • PDF
  • 使用SDWebImage进行图片缓存
  • 下载原始图像
  • 提取二维码(文本、URL)
  • 增量获取项目
  • 本地化
  • 3D Touch

需求

  • iOS 9.0+(在0.0.15或更高版本中停止支持iOS 8)
  • ARC
  • Swift 4.2 & 5

安装

CocoaPods

DKPhotoGallery可在CocoaPods上使用。只需将以下行添加到您的Podfile文件中

# For latest release in cocoapods
pod 'DKPhotoGallery'

Carthage

github "zhangao0086/DKPhotoGallery"

如果您使用Carthage来构建依赖项,请确保您已将DKPhotoGallery.frameworkSDWebImage.framework添加到目标的"链接框架和库"部分中,并在Carthage框架复制构建阶段中包含它们。

使用

let gallery = DKPhotoGallery()
gallery.singleTapMode = .dismiss
gallery.items = self.items
gallery.presentingFromImageView = self.imageView
gallery.presentationIndex = 0

gallery.finishedBlock = { dismissIndex, dismissItem in
    if item == dismissItem {
        return imageView
    } else {
        return nil
    }
}

self.present(photoGallery: gallery)

DKPhotoGalleryItem

使用UIImage、URL或PHAsset创建一个DKPhotoGalleryItem。

@objc
open class DKPhotoGalleryItem: NSObject {
    
    /// The image to be set initially, until the image request finishes.
    open var thumbnail: UIImage?
    
    open var image: UIImage?
    open var imageURL: URL?
    
    open var videoURL: URL?

    /// iOS 11 or higher required.
    @objc open var pdfURL: URL?
    
    /**
     DKPhotoGallery will automatically decide whether to create ImagePreview or PlayerPreview via the mediaType of the asset.
     
     See more: DKPhotoPreviewFactory.swift
     */
    open var asset: PHAsset?
    open var assetLocalIdentifier: String?
    
    /**
     Used for some optional features.
     
     For ImagePreview, you can enable the original image download feature with a key named DKPhotoGalleryItemExtraInfoKeyRemoteImageOriginalURL.
     */
    open var extraInfo: [String: Any]?
}

提取二维码

启用原始图片下载

let item = DKPhotoGalleryItem(imageURL: URL(string:"https://sz-preview.oss-cn-hangzhou.aliyuncs.com/pics/10003/b29259d837d4aaeef4b33c9dbc964a5b?x-oss-process=image/resize,m_lfit,h_512,w_512/quality,Q_80")!)
item.extraInfo = [
    DKPhotoGalleryItemExtraInfoKeyRemoteImageOriginalURL: URL(string:"https://sz-preview.oss-cn-hangzhou.aliyuncs.com/pics/10003/b29259d837d4aaeef4b33c9dbc964a5b")!
]

本地化

默认支持的语言

  • en.lproj
  • zh-Hans.lproj

您也可以添加一个钩子来返回您自己的本地化字符串

DKPhotoGalleryResource.customLocalizationBlock = { title in
    if title == "preview.image.longPress.cancel" {
        return "This is a test."
    } else {
        return nil
    }
}

许可

DKPhotoGallery是在MIT许可下发布的。有关详细信息,请参阅LICENSE文件。