QMUIImagePreviewView
@interface QMUIImagePreviewView
: UIView <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
查看图片的控件,支持横向滚动、放大缩小、loading 及错误语展示,内部使用 UICollectionView 实现横向滚动及 cell 复用,因此与其他普通的 UICollectionView 一样,也可使用 reloadData、collectionViewLayout 等常用方法。
使用方式:
- 使用 initWithFrame: 或 init 方法初始化。
- 设置 delegate。
- 在 delegate 的 numberOfImagesInImagePreviewView: 方法里返回图片总数。
- 在 delegate 的 imagePreviewView:renderZoomImageView:atIndex: 方法里为 zoomImageView.image 设置图片,如果需要,也可调用 [zoomImageView showLoading] 等方法来显示 loading。
- 由于 QMUIImagePreviewViewDelegate 继承自 QMUIZoomImageViewDelegate,所以若需要响应单击、双击、长按事件,请实现 QMUIZoomImageViewDelegate 里的对应方法。
- 若需要从指定的某一张图片开始查看,可使用 currentImageIndex 属性。
See
QMUIImagePreviewViewController-
Undocumented
Declaration
Objective-C
@property(nonatomic, weak) id<QMUIImagePreviewViewDelegate> delegate
Swift
weak var delegate: QMUIImagePreviewViewDelegate! { get set }
-
Undocumented
Declaration
Objective-C
@property(nonatomic, strong, readonly) UICollectionView *collectionView
Swift
var collectionView: UICollectionView! { get }
-
Undocumented
Declaration
Objective-C
@property(nonatomic, strong, readonly) QMUICollectionViewPagingLayout *collectionViewLayout
Swift
var collectionViewLayout: QMUICollectionViewPagingLayout! { get }
-
获取当前正在查看的图片 index,也可强制将图片滚动到指定的 index
Declaration
Objective-C
@property (nonatomic) NSUInteger currentImageIndex;
Swift
var currentImageIndex: UInt { get set }
-
Undocumented
Declaration
Objective-C
- (void)setCurrentImageIndex:(NSUInteger)currentImageIndex animated:(BOOL)animated;
Swift
func setCurrentImageIndex(_ currentImageIndex: UInt, animated: Bool)
-
每一页里的 loading 的颜色,默认为 UIColorWhite
Declaration
Objective-C
@property (nonatomic, strong) UIColor *loadingColor;
Swift
var loadingColor: UIColor! { get set }
-
获取某个 QMUIZoomImageView 所对应的 index
Declaration
Objective-C
- (NSInteger)indexForZoomImageView:(QMUIZoomImageView *)zoomImageView;
Swift
func index(for zoomImageView: QMUIZoomImageView!) -> Int
Return Value
zoomImageView 对应的 index,若当前的 zoomImageView 不可见,会返回 0
-
获取某个 index 对应的 zoomImageView
Declaration
Objective-C
- (QMUIZoomImageView *)zoomImageViewAtIndex:(NSUInteger)index;
Swift
func zoomImageView(at index: UInt) -> QMUIZoomImageView!
Return Value
指定的 index 所在的 zoomImageView,若该 index 对应的图片当前不可见(不处于可视区域),则返回 nil