QMUIImagePreviewViewController
@interface QMUIImagePreviewViewController <
UIViewControllerTransitioningDelegate>
图片预览控件,主要功能由内部自带的 QMUIImagePreviewView 提供,由于以 viewController 的形式存在,所以适用于那种在单独界面里展示图片,或者需要从某张目标图片的位置以动画的形式放大进入预览界面的场景。
使用方式:
- 使用 init 方法初始化
- 添加 self.imagePreviewView 的 delegate
- 以 push 或 present 的方式打开界面。如果是 present,则支持 QMUIImagePreviewViewControllerTransitioningStyle 里定义的动画。特别地,如果使用 zoom 方式,则需要通过 sourceImageView() 返回一个原界面上的 view 以作为 present 动画的起点和 dismiss 动画的终点。
See
QMUIImagePreviewView-
图片背后的黑色背景,默认为配置表里的 UIColorBlack
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *backgroundColor;
Swift
var backgroundColor: UIColor? { get set }
-
Undocumented
Declaration
Objective-C
@property(null_resettable, nonatomic, strong, readonly) QMUIImagePreviewView *imagePreviewView
Swift
var imagePreviewView: QMUIImagePreviewView! { get }
-
以 present 方式进入大图预览的时候使用的转场动画 animator,可通过 QMUIImagePreviewViewTransitionAnimator 提供的若干个 block 属性自定义动画,也可以完全重写一个自己的 animator。
Declaration
Objective-C
@property (nonatomic, strong, nullable) __kindof QMUIImagePreviewViewTransitionAnimator *transitioningAnimator;
Swift
var transitioningAnimator: QMUIImagePreviewViewTransitionAnimator? { get set }
-
present 时的动画,默认为 fade,当修改了 presentingStyle 时会自动把 dismissingStyle 也修改为相同的值。
Declaration
Objective-C
@property (nonatomic) QMUIImagePreviewViewControllerTransitioningStyle presentingStyle;
Swift
var presentingStyle: QMUIImagePreviewViewControllerTransitioningStyle { get set }
-
dismiss 时的动画,默认为 fade,默认与 presentingStyle 的值相同,若需要与之不同,请在设置完 presentingStyle 之后再设置 dismissingStyle。
Declaration
Objective-C
@property (nonatomic) QMUIImagePreviewViewControllerTransitioningStyle dismissingStyle;
Swift
var dismissingStyle: QMUIImagePreviewViewControllerTransitioningStyle { get set }
-
当以 zoom 动画进入/退出大图预览时,会通过这个 block 获取到原本界面上的图片所在的 view,从而进行动画的位置计算,如果返回的值为 nil,则会强制使用 fade 动画。当同时存在 sourceImageView 和 sourceImageRect 时,只有 sourceImageRect 会被调用。
Declaration
Objective-C
@property (nonatomic, copy, nullable) UIView *_Nullable (^)(void) sourceImageView;
Swift
var sourceImageView: (() -> UIView?)? { get set }
-
当以 zoom 动画进入/退出大图预览时,会通过这个 block 获取到原本界面上的图片所在的 view,从而进行动画的位置计算,如果返回的值为 CGRectZero,则会强制使用 fade 动画。注意返回值要进行坐标系转换。当同时存在 sourceImageView 和 sourceImageRect 时,只有 sourceImageRect 会被调用。
Declaration
Objective-C
@property (nonatomic, copy, nullable) CGRect (^)(void) sourceImageRect;
Swift
var sourceImageRect: (() -> CGRect)? { get set }
-
当以 zoom 动画进入/退出大图预览时,可以指定一个圆角值,默认为 QMUIImagePreviewViewControllerCornerRadiusAutomaticDimension,也即自动从 sourceImageView.layer.cornerRadius 获取,如果使用的是 sourceImageRect 或希望自定义圆角值,则直接给 sourceImageCornerRadius 赋值即可。
Declaration
Objective-C
@property (nonatomic) CGFloat sourceImageCornerRadius;
Swift
var sourceImageCornerRadius: CGFloat { get set }
-
是否支持手势拖拽退出预览模式,默认为 YES。仅对以 present 方式进入大图预览的场景有效。
Declaration
Objective-C
@property (nonatomic) BOOL dismissingGestureEnabled;
Swift
var dismissingGestureEnabled: Bool { get set }
-
Undocumented
Declaration
Objective-C
+ (instancetype)appearance;
Swift
class func appearance() -> Self