QMUIZoomImageView

@interface QMUIZoomImageView : UIView <UIScrollViewDelegate>

支持缩放查看静态图片、live photo、视频的控件 默认显示完整图片或视频,可双击查看原始大小,再次双击查看放大后的大小,第三次双击恢复到初始大小。

支持通过修改 contentMode 来控制静态图片和 live photo 默认的显示模式,目前仅支持 UIViewContentModeCenter、UIViewContentModeScaleAspectFill、UIViewContentModeScaleAspectFit,默认为 UIViewContentModeCenter。注意这里的显示模式是基于 viewportRect 而言的而非整个 zoomImageView

See

viewportRect

QMUIZoomImageView 提供最基础的图片预览和缩放功能以及 loading、错误等状态的展示支持,其他功能请通过继承来实现。

  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, weak) id<QMUIZoomImageViewDelegate> delegate

    Swift

    weak var delegate: QMUIZoomImageViewDelegate! { get set }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, readonly) UIScrollView *scrollView

    Swift

    var scrollView: UIScrollView! { get }
  • 比如常见的上传头像预览界面中间有一个用于裁剪的方框,则 viewportRect 必须被设置为这个方框在 zoomImageView 坐标系内的 frame,否则拖拽图片或视频时无法正确限制它们的显示范围

    Note

    图片或视频的初始位置会位于 viewportRect 正中间

    Note

    如果想要图片覆盖整个 viewportRect,将 contentMode 设置为 UIViewContentModeScaleAspectFill 即可 如果设置为 CGRectZero 则表示使用默认值,默认值为和整个 zoomImageView 一样大

    Declaration

    Objective-C

    @property (nonatomic) CGRect viewportRect;

    Swift

    var viewportRect: CGRect { get set }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, assign) CGFloat maximumZoomScale

    Swift

    var maximumZoomScale: CGFloat { get set }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, copy) NSObject<NSCopying> *reusedIdentifier

    Swift

    @NSCopying var reusedIdentifier: (NSCopying & NSObjectProtocol)! { get set }
  • 设置当前要显示的图片,会把 livePhoto/video 相关内容清空,因此注意不要直接通过 imageView.image 来设置图片。

    Declaration

    Objective-C

    @property (nonatomic, weak) UIImage *image;

    Swift

    weak var image: UIImage! { get set }
  • 用于显示图片的 UIImageView,注意不要通过 imageView.image 来设置图片,请使用 image 属性。

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) UIImageView *imageView;

    Swift

    var imageView: UIImageView! { get }
  • 设置当前要显示的 Live Photo,会把 image/video 相关内容清空,因此注意不要直接通过 livePhotoView.livePhoto 来设置

    Declaration

    Objective-C

    @property (nonatomic, weak) PHLivePhoto *livePhoto;

    Swift

    weak var livePhoto: PHLivePhoto! { get set }
  • 用于显示 Live Photo 的 view,仅在 iOS 9.1 及以后才有效

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) PHLivePhotoView *livePhotoView;

    Swift

    var livePhotoView: PHLivePhotoView! { get }
  • 设置当前要显示的 video ,会把 image/livePhoto 相关内容清空,因此注意不要直接通过 videoPlayerLayer 来设置

    Declaration

    Objective-C

    @property (nonatomic, weak) AVPlayerItem *videoPlayerItem;

    Swift

    weak var videoPlayerItem: AVPlayerItem! { get set }
  • 用于显示 video 的 layer

    Declaration

    Objective-C

    @property (nonatomic, weak, readonly) AVPlayerLayer *videoPlayerLayer;

    Swift

    weak var videoPlayerLayer: AVPlayerLayer! { get }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, readonly) QMUIZoomImageViewVideoToolbar *videoToolbar

    Swift

    var videoToolbar: QMUIZoomImageViewVideoToolbar! { get }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, assign) UIEdgeInsets videoToolbarMargins

    Swift

    var videoToolbarMargins: UIEdgeInsets { get set }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, readonly) QMUIButton *videoCenteredPlayButton

    Swift

    var videoCenteredPlayButton: QMUIButton! { get }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong) UIImage *videoCenteredPlayButtonImage

    Swift

    var videoCenteredPlayButtonImage: UIImage! { get set }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong) QMUIPieProgressView *cloudProgressView

    Swift

    var cloudProgressView: QMUIPieProgressView! { get set }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong) QMUIButton *cloudDownloadRetryButton

    Swift

    var cloudDownloadRetryButton: QMUIButton! { get set }
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, assign) QMUIAssetDownloadStatus cloudDownloadStatus

    Swift

    var cloudDownloadStatus: Int32 { get set }
  • 暂停视频播放

    Declaration

    Objective-C

    - (void)pauseVideo;

    Swift

    func pauseVideo()
  • 停止视频播放,将播放状态重置到初始状态

    Declaration

    Objective-C

    - (void)endPlayingVideo;

    Swift

    func endPlayingVideo()
  • 获取当前正在显示的图片/视频的容器

    Declaration

    Objective-C

    @property (nonatomic, weak, readonly) __kindof UIView *contentView;

    Swift

    weak var contentView: UIView! { get }
  • 获取当前正在显示的图片/视频在整个 QMUIZoomImageView 坐标系里的 rect(会按照当前的缩放状态来计算)

    Declaration

    Objective-C

    - (CGRect)contentViewRectInZoomImageView;

    Swift

    func contentViewRectInZoomImageView() -> CGRect
  • 重置图片或视频的大小,使用的场景例如:相册控件里放大当前图片、划到下一张、再回来,当前的图片或视频应该恢复到原来大小。 注意子类重写需要调一下super。

    Declaration

    Objective-C

    - (void)revertZooming;

    Swift

    func revertZooming()
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, readonly) QMUIEmptyView *emptyView

    Swift

    var emptyView: QMUIEmptyView! { get }
  • 显示一个 loading @info 注意 cell 复用可能导致当前页面显示一张错误的旧图片/视频,所以一般情况下需要视情况同时将 image/livePhoto/videoPlayerItem 等属性置为 nil 以清除图片/视频的显示

    Declaration

    Objective-C

    - (void)showLoading;

    Swift

    func showLoading()
  • 显示一句提示语 @info 注意 cell 复用可能导致当前页面显示一张错误的旧图片/视频,所以一般情况下需要视情况同时将 image/livePhoto/videoPlayerItem 等属性置为 nil 以清除图片/视频的显示

    Declaration

    Objective-C

    - (void)showEmptyViewWithText:(NSString *)text;

    Swift

    func showEmpty(withText text: String!)
  • Undocumented

    Declaration

    Objective-C

    - (void)showEmptyViewWithText:(NSString *)text
                       detailText:(NSString *)detailText
                      buttonTitle:(NSString *)buttonTitle
                     buttonTarget:(id)buttonTarget
                     buttonAction:(SEL)action;

    Swift

    func showEmpty(withText text: String!, detailText: String!, buttonTitle: String!, buttonTarget: Any!, buttonAction action: Selector!)
  • 将 emptyView 隐藏

    Declaration

    Objective-C

    - (void)hideEmptyView;

    Swift

    func hideEmpty()