Commit 9536f08a authored by tanzhen's avatar tanzhen

TZImageManager类新增获得下标为index照片的方法

parent 28fb3ac5
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
- (void)getCameraRollAlbum:(BOOL)allowPickingVideo completion:(void (^)(TZAlbumModel *model))completion; - (void)getCameraRollAlbum:(BOOL)allowPickingVideo completion:(void (^)(TZAlbumModel *model))completion;
- (void)getAllAlbums:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAlbumModel *> *models))completion; - (void)getAllAlbums:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAlbumModel *> *models))completion;
/// Get Asset 获得Asset数组 /// Get Assets 获得Asset数组
- (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAssetModel *> *models))completion; - (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAssetModel *> *models))completion;
- (void)getAssetFromFetchResult:(id)result atIndex:(NSInteger)index allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(TZAssetModel *model))completion;
/// Get photo 获得照片 /// Get photo 获得照片
- (void)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion; - (void)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion;
......
...@@ -127,9 +127,9 @@ ...@@ -127,9 +127,9 @@
} }
} }
#pragma mark - Get Asset #pragma mark - Get Assets
/// Get Asset 获得照片数组 /// Get Assets 获得照片数组
- (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAssetModel *> *))completion { - (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(NSArray<TZAssetModel *> *))completion {
NSMutableArray *photoArr = [NSMutableArray array]; NSMutableArray *photoArr = [NSMutableArray array];
if ([result isKindOfClass:[PHFetchResult class]]) { if ([result isKindOfClass:[PHFetchResult class]]) {
...@@ -175,6 +175,51 @@ ...@@ -175,6 +175,51 @@
} }
} }
/// Get asset at index 获得下标为index的单个照片
- (void)getAssetFromFetchResult:(id)result atIndex:(NSInteger)index allowPickingVideo:(BOOL)allowPickingVideo completion:(void (^)(TZAssetModel *))completion {
if ([result isKindOfClass:[PHFetchResult class]]) {
PHFetchResult *fetchResult = (PHFetchResult *)result;
PHAsset *asset = fetchResult[index];
TZAssetModelMediaType type = TZAssetModelMediaTypePhoto;
if (asset.mediaType == PHAssetMediaTypeVideo) type = TZAssetModelMediaTypeVideo;
else if (asset.mediaType == PHAssetMediaTypeAudio) type = TZAssetModelMediaTypeAudio;
else if (asset.mediaType == PHAssetMediaTypeImage) {
if (iOS9_1Later) {
// if (asset.mediaSubtypes == PHAssetMediaSubtypePhotoLive) type = TZAssetModelMediaTypeLivePhoto;
}
}
NSString *timeLength = type == TZAssetModelMediaTypeVideo ? [NSString stringWithFormat:@"%0.0f",asset.duration] : @"";
timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue];
TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:type timeLength:timeLength];
if (completion) completion(model);
} else if ([result isKindOfClass:[ALAssetsGroup class]]) {
ALAssetsGroup *gruop = (ALAssetsGroup *)result;
if (!allowPickingVideo) [gruop setAssetsFilter:[ALAssetsFilter allPhotos]];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
[gruop enumerateAssetsAtIndexes:indexSet options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
TZAssetModel *model;
TZAssetModelMediaType type = TZAssetModelMediaTypePhoto;
if (!allowPickingVideo){
model = [TZAssetModel modelWithAsset:result type:type];
if (completion) completion(model);
return;
}
/// Allow picking video
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
type = TZAssetModelMediaTypeVideo;
NSTimeInterval duration = [[result valueForProperty:ALAssetPropertyDuration] integerValue];
NSString *timeLength = [NSString stringWithFormat:@"%0.0f",duration];
timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue];
model = [TZAssetModel modelWithAsset:result type:type timeLength:timeLength];
} else {
model = [TZAssetModel modelWithAsset:result type:type];
}
if (completion) completion(model);
}];
}
}
- (NSString *)getNewTimeFromDurationSecond:(NSInteger)duration { - (NSString *)getNewTimeFromDurationSecond:(NSInteger)duration {
NSString *newTime; NSString *newTime;
if (duration < 10) { if (duration < 10) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment