Skip to content

Commit 8fc5610

Browse files
committed
1. 修复预览某些视频时视频尺寸错误的 bug;2. requestImageData: 方法增加图片信息的获取;3. 增加 QMUIMarqueeLabel 的 Demo;
1 parent 51ab16a commit 8fc5610

19 files changed

Lines changed: 406 additions & 67 deletions

QMUI/QMUIKit/UIComponents/AssetLibrary/QMUIAsset.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typedef NS_ENUM(NSUInteger, QMUIAssetDownloadStatus) {
7272
*
7373
* @return 返回请求图片的请求 id
7474
*/
75-
- (NSInteger)requestOriginImageWithCompletion:(void (^)(UIImage *result, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler;
75+
- (NSInteger)requestOriginImageWithCompletion:(void (^)(UIImage *result, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler;
7676

7777
/**
7878
* 异步请求 Asset 的缩略图,不会产生网络请求
@@ -83,7 +83,7 @@ typedef NS_ENUM(NSUInteger, QMUIAssetDownloadStatus) {
8383
*
8484
* @return 返回请求图片的请求 id
8585
*/
86-
- (NSInteger)requestThumbnailImageWithSize:(CGSize)size completion:(void (^)(UIImage *result, NSDictionary *info))completion;
86+
- (NSInteger)requestThumbnailImageWithSize:(CGSize)size completion:(void (^)(UIImage *result, NSDictionary<NSString *, id> *info))completion;
8787

8888
/**
8989
* 异步请求 Asset 的预览图,可能会有网络请求
@@ -96,7 +96,7 @@ typedef NS_ENUM(NSUInteger, QMUIAssetDownloadStatus) {
9696
*
9797
* @return 返回请求图片的请求 id
9898
*/
99-
- (NSInteger)requestPreviewImageWithCompletion:(void (^)(UIImage *result, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler;
99+
- (NSInteger)requestPreviewImageWithCompletion:(void (^)(UIImage *result, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler;
100100

101101
/**
102102
* 异步请求 Live Photo,可能会有网络请求
@@ -108,7 +108,7 @@ typedef NS_ENUM(NSUInteger, QMUIAssetDownloadStatus) {
108108
*
109109
* @return 返回请求图片的请求 id
110110
*/
111-
- (NSInteger)requestLivePhotoWithCompletion:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler NS_AVAILABLE_IOS(9_1);
111+
- (NSInteger)requestLivePhotoWithCompletion:(void (^)(PHLivePhoto *livePhoto, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler NS_AVAILABLE_IOS(9_1);
112112

113113
/**
114114
* 异步请求 AVPlayerItem,可能会有网络请求
@@ -120,14 +120,16 @@ typedef NS_ENUM(NSUInteger, QMUIAssetDownloadStatus) {
120120
*
121121
* @return 返回请求 AVPlayerItem 的请求 id
122122
*/
123-
- (NSInteger)requestPlayerItemWithCompletion:(void (^)(AVPlayerItem *playerItem, NSDictionary *info))completion withProgressHandler:(PHAssetVideoProgressHandler)phProgressHandler;
123+
- (NSInteger)requestPlayerItemWithCompletion:(void (^)(AVPlayerItem *playerItem, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetVideoProgressHandler)phProgressHandler;
124124

125125
/**
126-
* 获取图片的 Data
126+
* 异步请求图片的 Data
127127
*
128128
* @param completion 完成请求后调用的 block,参数中包含了请求的图片 Data(若 assetType 不是 QMUIAssetTypeImage 或 QMUIAssetTypeLivePhoto 则为 nil),以及该图片是否为 GIF 的判断值
129+
*
130+
* @wraning iOS 8.0 以下中并没有异步请求 Data 的接口,因此实际上为同步请求,这时 block 中的第二个参数(图片信息)返回的为 nil。
129131
*/
130-
- (void)requestImageData:(void (^)(NSData *imageData, BOOL isGif))completion;
132+
- (void)requestImageData:(void (^)(NSData *imageData, NSDictionary<NSString *, id> *info, BOOL isGif))completion;
131133

132134
/**
133135
* 获取图片的 UIImageOrientation 值,仅 assetType 为 QMUIAssetTypeImage 或 QMUIAssetTypeLivePhoto 时有效

QMUI/QMUIKit/UIComponents/AssetLibrary/QMUIAsset.m

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#import "QMUIAssetsManager.h"
1515
#import "NSString+QMUI.h"
1616

17+
static NSString * const kAssetInfoImageData = @"imageData";
18+
static NSString * const kAssetInfoOriginInfo = @"originInfo";
19+
static NSString * const kAssetInfoDataUTI = @"dataUTI";
20+
static NSString * const kAssetInfoOrientation = @"orientation";
21+
static NSString * const kAssetInfoSize = @"size";
22+
1723
@interface QMUIAsset ()
1824

1925
@property (nonatomic, assign, readwrite) QMUIAssetType assetType;
@@ -159,7 +165,7 @@ - (UIImage *)previewImage {
159165
return resultImage;
160166
}
161167

162-
- (NSInteger)requestOriginImageWithCompletion:(void (^)(UIImage *result, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler {
168+
- (NSInteger)requestOriginImageWithCompletion:(void (^)(UIImage *result, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler {
163169
if (_usePhotoKit) {
164170
PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init];
165171
imageRequestOptions.networkAccessAllowed = YES; // 允许访问网络
@@ -177,7 +183,7 @@ - (NSInteger)requestOriginImageWithCompletion:(void (^)(UIImage *result, NSDicti
177183
}
178184
}
179185

180-
- (NSInteger)requestThumbnailImageWithSize:(CGSize)size completion:(void (^)(UIImage *result, NSDictionary *info))completion {
186+
- (NSInteger)requestThumbnailImageWithSize:(CGSize)size completion:(void (^)(UIImage *result, NSDictionary<NSString *, id> *info))completion {
181187
if (_usePhotoKit) {
182188
PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init];
183189
imageRequestOptions.resizeMode = PHImageRequestOptionsResizeModeFast;
@@ -196,7 +202,7 @@ - (NSInteger)requestThumbnailImageWithSize:(CGSize)size completion:(void (^)(UII
196202
}
197203
}
198204

199-
- (NSInteger)requestPreviewImageWithCompletion:(void (^)(UIImage *result, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler {
205+
- (NSInteger)requestPreviewImageWithCompletion:(void (^)(UIImage *result, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler {
200206
if (_usePhotoKit) {
201207
PHImageRequestOptions *imageRequestOptions = [[PHImageRequestOptions alloc] init];
202208
imageRequestOptions.networkAccessAllowed = YES; // 允许访问网络
@@ -214,7 +220,7 @@ - (NSInteger)requestPreviewImageWithCompletion:(void (^)(UIImage *result, NSDict
214220
}
215221
}
216222

217-
- (NSInteger)requestLivePhotoWithCompletion:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler {
223+
- (NSInteger)requestLivePhotoWithCompletion:(void (^)(PHLivePhoto *livePhoto, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetImageProgressHandler)phProgressHandler {
218224
if (_usePhotoKit && [[PHCachingImageManager class] instancesRespondToSelector:@selector(requestLivePhotoForAsset:targetSize:contentMode:options:resultHandler:)]) {
219225
PHLivePhotoRequestOptions *livePhotoRequestOptions = [[PHLivePhotoRequestOptions alloc] init];
220226
livePhotoRequestOptions.networkAccessAllowed = YES; // 允许访问网络
@@ -229,7 +235,7 @@ - (NSInteger)requestLivePhotoWithCompletion:(void (^)(PHLivePhoto *livePhoto, NS
229235
}
230236
}
231237

232-
- (NSInteger)requestPlayerItemWithCompletion:(void (^)(AVPlayerItem *playerItem, NSDictionary *info))completion withProgressHandler:(PHAssetVideoProgressHandler)phProgressHandler {
238+
- (NSInteger)requestPlayerItemWithCompletion:(void (^)(AVPlayerItem *playerItem, NSDictionary<NSString *, id> *info))completion withProgressHandler:(PHAssetVideoProgressHandler)phProgressHandler {
233239
if (_usePhotoKit && [[PHCachingImageManager class] instancesRespondToSelector:@selector(requestPlayerItemForVideo:options:resultHandler:)]) {
234240
PHVideoRequestOptions *videoRequestOptions = [[PHVideoRequestOptions alloc] init];
235241
videoRequestOptions.networkAccessAllowed = YES; // 允许访问网络
@@ -249,10 +255,10 @@ - (NSInteger)requestPlayerItemWithCompletion:(void (^)(AVPlayerItem *playerItem,
249255
}
250256
}
251257

252-
- (void)requestImageData:(void (^)(NSData *imageData, BOOL isGif))completion {
258+
- (void)requestImageData:(void (^)(NSData *imageData, NSDictionary<NSString *, id> *info, BOOL isGif))completion {
253259
if (self.assetType != QMUIAssetTypeImage && self.assetType != QMUIAssetTypeLivePhoto) {
254260
if (completion) {
255-
completion(nil, NO);
261+
completion(nil, nil, NO);
256262
}
257263
return;
258264
}
@@ -262,22 +268,24 @@ - (void)requestImageData:(void (^)(NSData *imageData, BOOL isGif))completion {
262268
[self requestPhAssetInfo:^(NSDictionary *phAssetInfo) {
263269
_phAssetInfo = phAssetInfo;
264270
if (completion) {
265-
NSString *dataUTI = phAssetInfo[@"dataUTI"];
271+
NSString *dataUTI = phAssetInfo[kAssetInfoDataUTI];
266272
BOOL isGif = [dataUTI isEqualToString:(__bridge NSString *)kUTTypeGIF];
273+
NSDictionary<NSString *, id> *originInfo = phAssetInfo[kAssetInfoOriginInfo];
267274
/**
268275
* 这里不在主线程执行,若用户在该 block 中操作 UI 时会产生一些问题,
269276
* 为了避免这种情况,这里该 block 主动放到主线程执行。
270277
*/
271278
dispatch_async(dispatch_get_main_queue(), ^{
272-
completion(phAssetInfo[@"imageData"], isGif);
279+
completion(phAssetInfo[kAssetInfoImageData], originInfo, isGif);
273280
});
274281
}
275282
}];
276283
} else {
277284
if (completion) {
278-
NSString *dataUTI = _phAssetInfo[@"dataUTI"];
285+
NSString *dataUTI = _phAssetInfo[kAssetInfoDataUTI];
279286
BOOL isGif = [dataUTI isEqualToString:(__bridge NSString *)kUTTypeGIF];
280-
completion(_phAssetInfo[@"imageData"], isGif);
287+
NSDictionary<NSString *, id> *originInfo = _phAssetInfo[kAssetInfoOriginInfo];
288+
completion(_phAssetInfo[kAssetInfoImageData], originInfo, isGif);
281289
}
282290
}
283291
} else {
@@ -292,9 +300,9 @@ - (void)requestImageData:(void (^)(NSData *imageData, BOOL isGif))completion {
292300
// 判断是否为 GIF 图
293301
ALAssetRepresentation *gifRepresentation = [_alAsset representationForUTI: (__bridge NSString *)kUTTypeGIF];
294302
if (gifRepresentation) {
295-
completion(imageData, YES);
303+
completion(imageData, nil, YES);
296304
} else {
297-
completion(imageData, NO);
305+
completion(imageData, nil, NO);
298306
}
299307
}];
300308
}
@@ -312,7 +320,7 @@ - (UIImageOrientation)imageOrientation {
312320
} synchronous:YES];
313321
}
314322
// 从 PhAssetInfo 中获取 UIImageOrientation 对应的字段
315-
orientation = (UIImageOrientation)[_phAssetInfo[@"orientation"] integerValue];
323+
orientation = (UIImageOrientation)[_phAssetInfo[kAssetInfoOrientation] integerValue];
316324
} else {
317325
orientation = (UIImageOrientation)[[_alAsset valueForProperty:@"ALAssetPropertyOrientation"] integerValue];
318326
}
@@ -347,13 +355,13 @@ - (void)requestPhAssetInfo:(void (^)(NSDictionary *))completion {
347355
if ([asset isKindOfClass:[AVURLAsset class]]) {
348356
NSMutableDictionary *tempInfo = [[NSMutableDictionary alloc] init];
349357
if (info) {
350-
[tempInfo addEntriesFromDictionary:info];
358+
[tempInfo setObject:info forKey:kAssetInfoOriginInfo];
351359
}
352360

353361
AVURLAsset *urlAsset = (AVURLAsset*)asset;
354362
NSNumber *size;
355363
[urlAsset.URL getResourceValue:&size forKey:NSURLFileSizeKey error:nil];
356-
[tempInfo setObject:size forKey:@"size"];
364+
[tempInfo setObject:size forKey:kAssetInfoSize];
357365
if (completion) {
358366
completion(tempInfo);
359367
}
@@ -375,14 +383,14 @@ - (void)requestImagePhAssetInfo:(void (^)(NSDictionary *))completion synchronous
375383
[[[QMUIAssetsManager sharedInstance] phCachingImageManager] requestImageDataForAsset:_phAsset options:imageRequestOptions resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
376384
if (info) {
377385
NSMutableDictionary *tempInfo = [[NSMutableDictionary alloc] init];
378-
[tempInfo setObject:imageData forKey:@"imageData"];
386+
[tempInfo setObject:imageData forKey:kAssetInfoImageData];
379387

380-
[tempInfo addEntriesFromDictionary:info];
388+
[tempInfo setObject:info forKey:kAssetInfoOriginInfo];
381389
if (dataUTI) {
382-
[tempInfo setObject:dataUTI forKey:@"dataUTI"]; // TODO: kayo 这个字段对应的是不是就是文件的 data?换句话说,要支持 GIF 就要从这里获取 data?
390+
[tempInfo setObject:dataUTI forKey:kAssetInfoDataUTI];
383391
}
384-
[tempInfo setObject:@(orientation) forKey:@"orientation"];
385-
[tempInfo setObject:@(imageData.length) forKey:@"size"];
392+
[tempInfo setObject:@(orientation) forKey:kAssetInfoOrientation];
393+
[tempInfo setObject:@(imageData.length) forKey:kAssetInfoSize];
386394
if (completion) {
387395
completion(tempInfo);
388396
}
@@ -411,13 +419,13 @@ - (void)assetSize:(void (^)(long long size))completion {
411419
* 为了避免这种情况,这里该 block 主动放到主线程执行。
412420
*/
413421
dispatch_async(dispatch_get_main_queue(), ^{
414-
completion([phAssetInfo[@"size"] longLongValue]);
422+
completion([phAssetInfo[kAssetInfoSize] longLongValue]);
415423
});
416424
}
417425
}];
418426
} else {
419427
if (completion) {
420-
completion([_phAssetInfo[@"size"] longLongValue]);
428+
completion([_phAssetInfo[kAssetInfoSize] longLongValue]);
421429
}
422430
}
423431
} else {

QMUI/QMUIKit/UIComponents/ImagePickerLibrary/QMUIAlbumViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
229229
// 显示相册名称
230230
cell.textLabel.text = [assetsGroup name];
231231
// 显示相册中所包含的资源数量
232-
cell.detailTextLabel.text = [NSString stringWithFormat:@"(%ld)", (long)assetsGroup.numberOfAssets];
232+
cell.detailTextLabel.text = [NSString stringWithFormat:@"(%@)", @(assetsGroup.numberOfAssets)];
233233

234234
[cell updateCellAppearanceWithIndexPath:indexPath];
235235

QMUI/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerPreviewViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
@property(nonatomic, strong) NSMutableArray<QMUIAsset *> *selectedImageAssetArray;
5252

5353
@property(nonatomic, assign) QMUIAssetDownloadStatus downloadStatus;
54-
@property(nonatomic, assign) NSInteger maximumSelectImageCount; // 最多可以选择的图片数,默认为无穷大
55-
@property(nonatomic, assign) NSInteger minimumSelectImageCount; // 最少需要选择的图片数,默认为 0
54+
@property(nonatomic, assign) NSUInteger maximumSelectImageCount; // 最多可以选择的图片数,默认为无穷大
55+
@property(nonatomic, assign) NSUInteger minimumSelectImageCount; // 最少需要选择的图片数,默认为 0
5656
@property(nonatomic, copy) NSString *alertTitleWhenExceedMaxSelectImageCount; // 选择图片超出最大图片限制时 alertView 的标题
5757
@property(nonatomic, copy) NSString *alertButtonTitleWhenExceedMaxSelectImageCount; // 选择图片超出最大图片限制时 alertView 的标题
5858

QMUI/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerPreviewViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ - (void)handleCheckButtonClick:(id)sender {
278278
} else {
279279
if ([self.selectedImageAssetArray count] >= self.maximumSelectImageCount) {
280280
if (!self.alertTitleWhenExceedMaxSelectImageCount) {
281-
self.alertTitleWhenExceedMaxSelectImageCount = [NSString stringWithFormat:@"你最多只能选择%lu张图片", (long)self.maximumSelectImageCount];
281+
self.alertTitleWhenExceedMaxSelectImageCount = [NSString stringWithFormat:@"你最多只能选择%@张图片", @(self.maximumSelectImageCount)];
282282
}
283283
if (!self.alertButtonTitleWhenExceedMaxSelectImageCount) {
284284
self.alertButtonTitleWhenExceedMaxSelectImageCount = [NSString stringWithFormat:@"我知道了"];

QMUI/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
@property(nonatomic, strong) NSMutableArray<QMUIAsset *> *selectedImageAssetArray; // 当前被选择的图片对应的 QMUIAsset 对象数组
112112

113113
@property(nonatomic, assign) BOOL allowsMultipleSelection; // 是否允许图片多选,默认为 YES。如果为 NO,则不显示 checkbox 和底部工具栏。
114-
@property(nonatomic, assign) NSInteger maximumSelectImageCount; // 最多可以选择的图片数,默认为无符号整形数的最大值,相当于没有限制
115-
@property(nonatomic, assign) NSInteger minimumSelectImageCount; // 最少需要选择的图片数,默认为 0
114+
@property(nonatomic, assign) NSUInteger maximumSelectImageCount; // 最多可以选择的图片数,默认为无符号整形数的最大值,相当于没有限制
115+
@property(nonatomic, assign) NSUInteger minimumSelectImageCount; // 最少需要选择的图片数,默认为 0
116116
@property(nonatomic, copy) NSString *alertTitleWhenExceedMaxSelectImageCount; // 选择图片超出最大图片限制时 alertView 的标题
117117
@property(nonatomic, copy) NSString *alertButtonTitleWhenExceedMaxSelectImageCount; // 选择图片超出最大图片限制时 alertView 底部按钮的标题
118118

QMUI/QMUIKit/UIComponents/ImagePickerLibrary/QMUIImagePickerViewController.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ - (void)viewWillAppear:(BOOL)animated {
189189
// 如果有图片被选择,则预览按钮和发送按钮可点击,并刷新当前被选中的图片数量
190190
self.previewButton.enabled = YES;
191191
self.sendButton.enabled = YES;
192-
self.imageCountLabel.text = [NSString stringWithFormat:@"%ld", (long)selectedImageCount];
192+
self.imageCountLabel.text = [NSString stringWithFormat:@"%@", @(selectedImageCount)];
193193
self.imageCountLabel.hidden = NO;
194194
} else {
195195
// 如果没有任何图片被选择,则预览和发送按钮不可点击,并且隐藏显示图片数量的 Label
@@ -481,7 +481,7 @@ - (void)updateImageCountAndCheckLimited {
481481
if (selectedImageCount > 0 && selectedImageCount >= _minimumSelectImageCount) {
482482
self.previewButton.enabled = YES;
483483
self.sendButton.enabled = YES;
484-
self.imageCountLabel.text = [NSString stringWithFormat:@"%ld", (long)selectedImageCount];
484+
self.imageCountLabel.text = [NSString stringWithFormat:@"%@", @(selectedImageCount)];
485485
self.imageCountLabel.hidden = NO;
486486
[QMUIImagePickerHelper springAnimationOfImageSelectedCountChangeWithCountLabel:self.imageCountLabel];
487487
} else {
@@ -508,7 +508,7 @@ - (void)requestImageWithIndexPath:(NSIndexPath *)indexPath {
508508

509509
if ([_selectedImageAssetArray count] >= _maximumSelectImageCount) {
510510
if (!_alertTitleWhenExceedMaxSelectImageCount) {
511-
_alertTitleWhenExceedMaxSelectImageCount = [NSString stringWithFormat:@"你最多只能选择%lu张图片", (unsigned long)_maximumSelectImageCount];
511+
_alertTitleWhenExceedMaxSelectImageCount = [NSString stringWithFormat:@"你最多只能选择%@张图片", @(_maximumSelectImageCount)];
512512
}
513513
if (!_alertButtonTitleWhenExceedMaxSelectImageCount) {
514514
_alertButtonTitleWhenExceedMaxSelectImageCount = [NSString stringWithFormat:@"我知道了"];

QMUI/QMUIKit/UIComponents/QMUIImagePreviewView.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,12 @@ - (BOOL)enabledZoomViewInZoomImageView:(QMUIZoomImageView *)imageView {
290290
return YES;
291291
}
292292

293+
- (UIEdgeInsets)contentInsetsForVideoToolbar:(QMUIZoomImageViewVideoToolbar *)toolbar inZoomingImageView:(QMUIZoomImageView *)zoomImageView {
294+
[self checkIfDelegateMissing];
295+
if ([self.delegate respondsToSelector:_cmd]) {
296+
return [self.delegate contentInsetsForVideoToolbar:toolbar inZoomingImageView:zoomImageView];
297+
}
298+
return toolbar.contentInsets;
299+
}
300+
293301
@end

0 commit comments

Comments
 (0)