ImagePreviewView
@MainActor
open class ImagePreviewView : UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, ZoomImageViewDelegate
查看图片的控件,支持横向滚动、放大缩小、loading 及错误语展示,内部使用 UICollectionView 实现横向滚动及 cell 复用,因此与其他普通的 UICollectionView 一样,也可使用 reloadData、collectionViewLayout 等常用方法。
使用方式:
- 使用 initWithFrame: 或 init 方法初始化。
- 设置 delegate。
- 在 delegate 的 numberOfImagesInImagePreviewView: 方法里返回图片总数。
- 在 delegate 的 imagePreviewView:renderZoomImageView:atIndex: 方法里为 zoomImageView.image 设置图片,如果需要,也可调用 [zoomImageView showLoading] 等方法来显示 loading。
- 由于 ImagePreviewViewDelegate 继承自 ZoomImageViewDelegate,所以若需要响应单击、双击、长按事件,请实现 ZoomImageViewDelegate 里的对应方法。
- 若需要从指定的某一张图片开始查看,可使用 currentImageIndex 属性。
-
事件代理
Declaration
Swift
@MainActor open weak var delegate: ImagePreviewViewDelegate?
-
当前图片数量
Declaration
Swift
@MainActor open var imageCount: Int { get }
-
获取当前正在查看的图片 index,也可强制将图片滚动到指定的 index
Declaration
Swift
@MainActor open var currentImageIndex: Int { get set }
-
图片数组,delegate不存在时调用,支持UIImage|PHLivePhoto|AVPlayerItem|NSURL|NSString等
Declaration
Swift
@MainActor open var imageURLs: [Any]?
-
自定义图片信息数组,默认未使用,可用于自定义内容展示,默认nil
Declaration
Swift
@MainActor open var imageInfos: [Any]?
-
占位图片句柄,仅imageURLs生效,默认nil
Declaration
Swift
@MainActor open var placeholderImage: ((_ index: Int) -> UIImage?)?
-
是否自动播放video,默认NO
Declaration
Swift
@MainActor open var autoplayVideo: Bool
-
自定义zoomImageView样式句柄,cellForItem方法自动调用,先于renderZoomImageView
Declaration
Swift
@MainActor open var customZoomImageView: ((_ zoomImageView: ZoomImageView, _ index: Int) -> Void)?
-
自定义渲染zoomImageView句柄,cellForItem方法自动调用,优先级低于delegate
Declaration
Swift
@MainActor open var renderZoomImageView: ((_ zoomImageView: ZoomImageView, _ index: Int) -> Void)?
-
自定义内容视图句柄,内容显示完成自动调用,优先级低于delegate
Declaration
Swift
@MainActor open var customZoomContentView: ((_ zoomImageView: ZoomImageView, _ contentView: UIView) -> Void)?
-
获取当前正在查看的zoomImageView,若当前 index 对应的图片不可见(不处于可视区域),则返回 nil
Declaration
Swift
@MainActor open weak var currentZoomImageView: ZoomImageView? { get }
-
集合视图
Declaration
Swift
@MainActor open lazy var collectionView: UICollectionView { get set }
-
结合视图布局
Declaration
Swift
@MainActor open lazy var collectionViewLayout: CollectionViewPagingLayout { get set }
-
Undocumented
Declaration
Swift
@MainActor override public init(frame: CGRect)
-
Undocumented
Declaration
Swift
@MainActor public required init?(coder: NSCoder)
-
Undocumented
Declaration
Swift
@MainActor override open func layoutSubviews()
-
将图片滚动到指定的 index
Declaration
Swift
@MainActor open func setCurrentImageIndex(_ currentImageIndex: Int, animated: Bool)
-
获取某个 ZoomImageView 所对应的 index,若当前的 zoomImageView 不可见,会返回nil
Declaration
Swift
@MainActor open func index(for zoomImageView: ZoomImageView) -> Int?
-
获取某个 index 对应的 zoomImageView,若该 index 对应的图片当前不可见(不处于可视区域),则返回 nil
Declaration
Swift
@MainActor open func zoomImageView(at index: Int) -> ZoomImageView?
-
Undocumented
Declaration
Swift
@MainActor open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
-
Undocumented
Declaration
Swift
@MainActor open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
-
Undocumented
Declaration
Swift
@MainActor open func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
-
Undocumented
Declaration
Swift
@MainActor open func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
-
Undocumented
Declaration
Swift
@MainActor open func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
-
Undocumented
Declaration
Swift
@MainActor open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
-
Undocumented
Declaration
Swift
@MainActor open func scrollViewDidScroll(_ scrollView: UIScrollView)
-
Declaration
Swift
@MainActor open func singleTouch(in zoomImageView: ZoomImageView, location: CGPoint)
-
Declaration
Swift
@MainActor open func doubleTouch(in zoomImageView: ZoomImageView, location: CGPoint)
-
Declaration
Swift
@MainActor open func longPress(in zoomImageView: ZoomImageView)
-
Declaration
Swift
@MainActor open func zoomImageView(_ zoomImageView: ZoomImageView, didHideVideoToolbar didHide: Bool)
-
Declaration
Swift
@MainActor open func zoomImageView(_ zoomImageView: ZoomImageView, customContentView contentView: UIView)
-
Declaration
Swift
@MainActor open func enabledZoomView(in zoomImageView: ZoomImageView) -> Bool