ImagePreviewView

open class ImagePreviewView : UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, ZoomImageViewDelegate

查看图片的控件,支持横向滚动、放大缩小、loading 及错误语展示,内部使用 UICollectionView 实现横向滚动及 cell 复用,因此与其他普通的 UICollectionView 一样,也可使用 reloadData、collectionViewLayout 等常用方法。

使用方式:

  1. 使用 initWithFrame: 或 init 方法初始化。
  2. 设置 delegate。
  3. 在 delegate 的 numberOfImagesInImagePreviewView: 方法里返回图片总数。
  4. 在 delegate 的 imagePreviewView:renderZoomImageView:atIndex: 方法里为 zoomImageView.image 设置图片,如果需要,也可调用 [zoomImageView showLoading] 等方法来显示 loading。
  5. 由于 ImagePreviewViewDelegate 继承自 ZoomImageViewDelegate,所以若需要响应单击、双击、长按事件,请实现 ZoomImageViewDelegate 里的对应方法。
  6. 若需要从指定的某一张图片开始查看,可使用 currentImageIndex 属性。

QMUI_iOS

  • 事件代理

    Declaration

    Swift

    open weak var delegate: ImagePreviewViewDelegate?
  • 当前图片数量

    Declaration

    Swift

    open var imageCount: Int { get }
  • 获取当前正在查看的图片 index,也可强制将图片滚动到指定的 index

    Declaration

    Swift

    open var currentImageIndex: Int { get set }
  • 图片数组,delegate不存在时调用,支持UIImage|PHLivePhoto|AVPlayerItem|NSURL|NSString等

    Declaration

    Swift

    open var imageURLs: [Any]?
  • 自定义图片信息数组,默认未使用,可用于自定义内容展示,默认nil

    Declaration

    Swift

    open var imageInfos: [Any]?
  • 占位图片句柄,仅imageURLs生效,默认nil

    Declaration

    Swift

    open var placeholderImage: ((_ index: Int) -> UIImage?)?
  • 是否自动播放video,默认NO

    Declaration

    Swift

    open var autoplayVideo: Bool
  • 自定义zoomImageView样式句柄,cellForItem方法自动调用,先于renderZoomImageView

    Declaration

    Swift

    open var customZoomImageView: ((_ zoomImageView: ZoomImageView, _ index: Int) -> Void)?
  • 自定义渲染zoomImageView句柄,cellForItem方法自动调用,优先级低于delegate

    Declaration

    Swift

    open var renderZoomImageView: ((_ zoomImageView: ZoomImageView, _ index: Int) -> Void)?
  • 自定义内容视图句柄,内容显示完成自动调用,优先级低于delegate

    Declaration

    Swift

    open var customZoomContentView: ((_ zoomImageView: ZoomImageView, _ contentView: UIView) -> Void)?
  • 获取当前正在查看的zoomImageView,若当前 index 对应的图片不可见(不处于可视区域),则返回 nil

    Declaration

    Swift

    open weak var currentZoomImageView: ZoomImageView? { get }
  • 集合视图

    Declaration

    Swift

    open lazy var collectionView: UICollectionView { get set }
  • 结合视图布局

    Declaration

    Swift

    open lazy var collectionViewLayout: CollectionViewPagingLayout { get set }
  • Undocumented

    Declaration

    Swift

    public override init(frame: CGRect)
  • Undocumented

    Declaration

    Swift

    public required init?(coder: NSCoder)
  • Undocumented

    Declaration

    Swift

    open override func layoutSubviews()
  • 将图片滚动到指定的 index

    Declaration

    Swift

    open func setCurrentImageIndex(_ currentImageIndex: Int, animated: Bool)
  • 获取某个 ZoomImageView 所对应的 index,若当前的 zoomImageView 不可见,会返回nil

    Declaration

    Swift

    open func index(for zoomImageView: ZoomImageView) -> Int?
  • 获取某个 index 对应的 zoomImageView,若该 index 对应的图片当前不可见(不处于可视区域),则返回 nil

    Declaration

    Swift

    open func zoomImageView(at index: Int) -> ZoomImageView?

UICollectionView

  • Undocumented

    Declaration

    Swift

    open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
  • Undocumented

    Declaration

    Swift

    open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
  • Undocumented

    Declaration

    Swift

    open func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
  • Undocumented

    Declaration

    Swift

    open func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
  • Undocumented

    Declaration

    Swift

    open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize

UIScrollViewDelegate

ZoomImageViewDelegate