Commit 9dd65241 authored by yuzheng.tz's avatar yuzheng.tz

1. 新增两个代理方法,isAlbumCanSelect:result:和isAssetCanSelect:,可由上层通过实现代理方法来决定某个相册/照片显示与否;

2. 优化gif图的预览体验,先显示静态本地缩略图,再加载gif动图;
3. 优化其他一些细节;
parent 5b6ff817
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "TZImagePickerController" s.name = "TZImagePickerController"
s.version = "1.7.9" s.version = "1.8.1"
s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video" s.summary = "A clone of UIImagePickerController, support picking multiple photos、original photo and video"
s.homepage = "https://github.com/banchichen/TZImagePickerController" s.homepage = "https://github.com/banchichen/TZImagePickerController"
s.license = "MIT" s.license = "MIT"
s.author = { "banchichen" => "tanzhenios@foxmail.com" } s.author = { "banchichen" => "tanzhenios@foxmail.com" }
s.platform = :ios s.platform = :ios
s.ios.deployment_target = "6.0" s.ios.deployment_target = "6.0"
s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.7.9" } s.source = { :git => "https://github.com/banchichen/TZImagePickerController.git", :tag => "1.8.1" }
s.requires_arc = true s.requires_arc = true
s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}" s.resources = "TZImagePickerController/TZImagePickerController/*.{png,xib,nib,bundle}"
s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}" s.source_files = "TZImagePickerController/TZImagePickerController/*.{h,m}"
......
...@@ -138,6 +138,9 @@ ...@@ -138,6 +138,9 @@
self.progressView.progress = progress; self.progressView.progress = progress;
self.progressView.hidden = NO; self.progressView.hidden = NO;
self.imageView.alpha = 0.4; self.imageView.alpha = 0.4;
if (progress >= 1) {
[self hideProgressView];
}
} else { } else {
*stop = YES; *stop = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
......
...@@ -12,12 +12,15 @@ ...@@ -12,12 +12,15 @@
#import <Photos/Photos.h> #import <Photos/Photos.h>
@class TZAlbumModel,TZAssetModel; @class TZAlbumModel,TZAssetModel;
@protocol TZImagePickerControllerDelegate;
@interface TZImageManager : NSObject @interface TZImageManager : NSObject
@property (nonatomic, strong) PHCachingImageManager *cachingImageManager; @property (nonatomic, strong) PHCachingImageManager *cachingImageManager;
+ (instancetype)manager NS_SWIFT_NAME(default()); + (instancetype)manager NS_SWIFT_NAME(default());
@property (assign, nonatomic) id<TZImagePickerControllerDelegate> pickerDelegate;
@property (nonatomic, assign) BOOL shouldFixOrientation; @property (nonatomic, assign) BOOL shouldFixOrientation;
/// Default is 600px / 默认600像素宽 /// Default is 600px / 默认600像素宽
...@@ -59,9 +62,10 @@ ...@@ -59,9 +62,10 @@
- (int32_t)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed; - (int32_t)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed;
/// Get full Image 获取原图 /// Get full Image 获取原图
/// 该方法一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。 /// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
- (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion; - (void)getOriginalPhotoWithAsset:(id)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion;
- (void)getOriginalPhotoWithAsset:(id)asset newCompletion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion; - (void)getOriginalPhotoWithAsset:(id)asset newCompletion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
// 该方法中,completion只会走一次
- (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion; - (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion;
/// Save photo 保存照片 /// Save photo 保存照片
......
...@@ -163,6 +163,13 @@ static CGFloat TZScreenScale; ...@@ -163,6 +163,13 @@ static CGFloat TZScreenScale;
if (![collection isKindOfClass:[PHAssetCollection class]]) continue; if (![collection isKindOfClass:[PHAssetCollection class]]) continue;
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:option]; PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:option];
if (fetchResult.count < 1) continue; if (fetchResult.count < 1) continue;
if ([self.pickerDelegate respondsToSelector:@selector(isAlbumCanSelect:result:)]) {
if (![self.pickerDelegate isAlbumCanSelect:collection.localizedTitle result:fetchResult]) {
continue;
}
}
if ([collection.localizedTitle containsString:@"Deleted"] || [collection.localizedTitle isEqualToString:@"最近删除"]) continue; if ([collection.localizedTitle containsString:@"Deleted"] || [collection.localizedTitle isEqualToString:@"最近删除"]) continue;
if ([self isCameraRollAlbum:collection.localizedTitle]) { if ([self isCameraRollAlbum:collection.localizedTitle]) {
[albumArr insertObject:[self modelWithResult:fetchResult name:collection.localizedTitle] atIndex:0]; [albumArr insertObject:[self modelWithResult:fetchResult name:collection.localizedTitle] atIndex:0];
...@@ -179,6 +186,13 @@ static CGFloat TZScreenScale; ...@@ -179,6 +186,13 @@ static CGFloat TZScreenScale;
} }
if ([group numberOfAssets] < 1) return; if ([group numberOfAssets] < 1) return;
NSString *name = [group valueForProperty:ALAssetsGroupPropertyName]; NSString *name = [group valueForProperty:ALAssetsGroupPropertyName];
if ([self.pickerDelegate respondsToSelector:@selector(isAlbumCanSelect:result:)]) {
if (![self.pickerDelegate isAlbumCanSelect:name result:group]) {
return;
}
}
if ([self isCameraRollAlbum:name]) { if ([self isCameraRollAlbum:name]) {
[albumArr insertObject:[self modelWithResult:group name:name] atIndex:0]; [albumArr insertObject:[self modelWithResult:group name:name] atIndex:0];
} else if ([name isEqualToString:@"My Photo Stream"] || [name isEqualToString:@"我的照片流"]) { } else if ([name isEqualToString:@"My Photo Stream"] || [name isEqualToString:@"我的照片流"]) {
...@@ -277,6 +291,12 @@ static CGFloat TZScreenScale; ...@@ -277,6 +291,12 @@ static CGFloat TZScreenScale;
} }
- (TZAssetModel *)assetModelWithAsset:(id)asset allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage { - (TZAssetModel *)assetModelWithAsset:(id)asset allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage {
BOOL canSelect = YES;
if ([self.pickerDelegate respondsToSelector:@selector(isAssetCanSelect:)]) {
canSelect = [self.pickerDelegate isAssetCanSelect:asset];
}
if (!canSelect) return nil;
TZAssetModel *model; TZAssetModel *model;
TZAssetModelMediaType type = TZAssetModelMediaTypePhoto; TZAssetModelMediaType type = TZAssetModelMediaTypePhoto;
if ([asset isKindOfClass:[PHAsset class]]) { if ([asset isKindOfClass:[PHAsset class]]) {
...@@ -313,7 +333,7 @@ static CGFloat TZScreenScale; ...@@ -313,7 +333,7 @@ static CGFloat TZScreenScale;
/// Allow picking video /// Allow picking video
if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) { if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
type = TZAssetModelMediaTypeVideo; type = TZAssetModelMediaTypeVideo;
NSTimeInterval duration = [[asset valueForProperty:ALAssetPropertyDuration] integerValue]; NSTimeInterval duration = [[asset valueForProperty:ALAssetPropertyDuration] doubleValue];
NSString *timeLength = [NSString stringWithFormat:@"%0.0f",duration]; NSString *timeLength = [NSString stringWithFormat:@"%0.0f",duration];
timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue]; timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue];
model = [TZAssetModel modelWithAsset:asset type:type timeLength:timeLength]; model = [TZAssetModel modelWithAsset:asset type:type timeLength:timeLength];
...@@ -429,11 +449,16 @@ static CGFloat TZScreenScale; ...@@ -429,11 +449,16 @@ static CGFloat TZScreenScale;
CGFloat pixelHeight = pixelWidth / aspectRatio; CGFloat pixelHeight = pixelWidth / aspectRatio;
imageSize = CGSizeMake(pixelWidth, pixelHeight); imageSize = CGSizeMake(pixelWidth, pixelHeight);
} }
__block UIImage *image;
// 修复获取图片时出现的瞬间内存过高问题 // 修复获取图片时出现的瞬间内存过高问题
// 下面两行代码,来自hsjcom,他的github是:https://github.com/hsjcom 表示感谢 // 下面两行代码,来自hsjcom,他的github是:https://github.com/hsjcom 表示感谢
PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init]; PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init];
option.resizeMode = PHImageRequestOptionsResizeModeFast; option.resizeMode = PHImageRequestOptionsResizeModeFast;
int32_t imageRequestID = [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { int32_t imageRequestID = [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
if (result) {
image = result;
}
BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]); BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]);
if (downloadFinined && result) { if (downloadFinined && result) {
result = [self fixOrientation:result]; result = [self fixOrientation:result];
...@@ -454,10 +479,11 @@ static CGFloat TZScreenScale; ...@@ -454,10 +479,11 @@ static CGFloat TZScreenScale;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
UIImage *resultImage = [UIImage imageWithData:imageData scale:0.1]; UIImage *resultImage = [UIImage imageWithData:imageData scale:0.1];
resultImage = [self scaleImage:resultImage toSize:imageSize]; resultImage = [self scaleImage:resultImage toSize:imageSize];
if (resultImage) { if (!resultImage) {
resultImage = [self fixOrientation:resultImage]; resultImage = image;
if (completion) completion(resultImage,info,[[info objectForKey:PHImageResultIsDegradedKey] boolValue]);
} }
resultImage = [self fixOrientation:resultImage];
if (completion) completion(resultImage,info,NO);
}]; }];
} }
}]; }];
...@@ -549,8 +575,7 @@ static CGFloat TZScreenScale; ...@@ -549,8 +575,7 @@ static CGFloat TZScreenScale;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { [[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]); BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]);
if (downloadFinined && imageData) { if (downloadFinined && imageData) {
BOOL isDegraded = [[info objectForKey:PHImageResultIsDegradedKey] boolValue]; if (completion) completion(imageData,info,NO);
if (completion) completion(imageData,info,isDegraded);
} }
}]; }];
} else if ([asset isKindOfClass:[ALAsset class]]) { } else if ([asset isKindOfClass:[ALAsset class]]) {
......
...@@ -112,7 +112,8 @@ ...@@ -112,7 +112,8 @@
@property (nonatomic, assign) NSInteger circleCropRadius; ///< 圆形裁剪框半径大小 @property (nonatomic, assign) NSInteger circleCropRadius; ///< 圆形裁剪框半径大小
@property (nonatomic, copy) void (^cropViewSettingBlock)(UIView *cropView); ///< 自定义裁剪框的其他属性 @property (nonatomic, copy) void (^cropViewSettingBlock)(UIView *cropView); ///< 自定义裁剪框的其他属性
- (void)showAlertWithTitle:(NSString *)title; - (id)showAlertWithTitle:(NSString *)title;
- (void)hideAlertView:(id)alertView;
- (void)showProgressHUD; - (void)showProgressHUD;
- (void)hideProgressHUD; - (void)hideProgressHUD;
@property (nonatomic, assign) BOOL isSelectOriginalPhoto; @property (nonatomic, assign) BOOL isSelectOriginalPhoto;
...@@ -199,6 +200,14 @@ ...@@ -199,6 +200,14 @@
// If user picking a gif image, this callback will be called. // If user picking a gif image, this callback will be called.
// 如果用户选择了一个gif图片,下面的handle会被执行 // 如果用户选择了一个gif图片,下面的handle会被执行
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(id)asset; - (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingGifImage:(UIImage *)animatedImage sourceAssets:(id)asset;
// Decide album show or not't
// 决定相册显示与否 albumName:相册名字 result:相册原始数据
- (BOOL)isAlbumCanSelect:(NSString *)albumName result:(id)result;
// Decide asset show or not't
// 决定照片显示与否
- (BOOL)isAssetCanSelect:(id)asset;
@end @end
......
...@@ -287,16 +287,30 @@ ...@@ -287,16 +287,30 @@
} }
} }
- (void)showAlertWithTitle:(NSString *)title { - (id)showAlertWithTitle:(NSString *)title {
if (iOS8Later) { if (iOS8Later) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"OK"] style:UIAlertActionStyleDefault handler:nil]]; [alertController addAction:[UIAlertAction actionWithTitle:[NSBundle tz_localizedStringForKey:@"OK"] style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alertController animated:YES completion:nil]; [self presentViewController:alertController animated:YES completion:nil];
return alertController;
} else { } else {
[[[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"OK"] otherButtonTitles:nil, nil] show]; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:[NSBundle tz_localizedStringForKey:@"OK"] otherButtonTitles:nil, nil];
[alertView show];
return alertView;
} }
} }
- (void)hideAlertView:(id)alertView {
if ([alertView isKindOfClass:[UIAlertController class]]) {
UIAlertController *alertC = alertView;
[alertC dismissViewControllerAnimated:YES completion:nil];
} else if ([alertView isKindOfClass:[UIAlertView class]]) {
UIAlertView *alertV = alertView;
[alertV dismissWithClickedButtonIndex:0 animated:YES];
}
alertView = nil;
}
- (void)showProgressHUD { - (void)showProgressHUD {
if (!_progressHUD) { if (!_progressHUD) {
_progressHUD = [UIButton buttonWithType:UIButtonTypeCustom]; _progressHUD = [UIButton buttonWithType:UIButtonTypeCustom];
...@@ -386,6 +400,11 @@ ...@@ -386,6 +400,11 @@
} }
} }
- (void)setPickerDelegate:(id<TZImagePickerControllerDelegate>)pickerDelegate {
_pickerDelegate = pickerDelegate;
[TZImageManager manager].pickerDelegate = pickerDelegate;
}
- (void)setColumnNumber:(NSInteger)columnNumber { - (void)setColumnNumber:(NSInteger)columnNumber {
_columnNumber = columnNumber; _columnNumber = columnNumber;
if (columnNumber <= 2) { if (columnNumber <= 2) {
...@@ -526,9 +545,6 @@ ...@@ -526,9 +545,6 @@
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:imagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:imagePickerVc action:@selector(cancelButtonClick)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:imagePickerVc.cancelBtnTitleStr style:UIBarButtonItemStylePlain target:imagePickerVc action:@selector(cancelButtonClick)];
// 1.6.10 采用微信的方式,只在相册列表页定义backBarButtonItem为返回,其余的顺系统的做法
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Back"] style:UIBarButtonItemStylePlain target:nil action:nil];
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
...@@ -541,6 +557,9 @@ ...@@ -541,6 +557,9 @@
self.navigationItem.title = [NSBundle tz_localizedStringForKey:@"Videos"]; self.navigationItem.title = [NSBundle tz_localizedStringForKey:@"Videos"];
} }
// 1.6.10 采用微信的方式,只在相册列表页定义backBarButtonItem为返回,其余的顺系统的做法
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSBundle tz_localizedStringForKey:@"Back"] style:UIBarButtonItemStylePlain target:nil action:nil];
[self configTableView]; [self configTableView];
} }
......
...@@ -312,6 +312,7 @@ static CGSize AssetGridThumbnailSize; ...@@ -312,6 +312,7 @@ static CGSize AssetGridThumbnailSize;
__block BOOL havenotShowAlert = YES; __block BOOL havenotShowAlert = YES;
[TZImageManager manager].shouldFixOrientation = YES; [TZImageManager manager].shouldFixOrientation = YES;
__block id alertView;
for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) { for (NSInteger i = 0; i < tzImagePickerVc.selectedModels.count; i++) {
TZAssetModel *model = tzImagePickerVc.selectedModels[i]; TZAssetModel *model = tzImagePickerVc.selectedModels[i];
[[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) { [[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
...@@ -326,16 +327,20 @@ static CGSize AssetGridThumbnailSize; ...@@ -326,16 +327,20 @@ static CGSize AssetGridThumbnailSize;
for (id item in photos) { if ([item isKindOfClass:[NSNumber class]]) return; } for (id item in photos) { if ([item isKindOfClass:[NSNumber class]]) return; }
if (havenotShowAlert) { if (havenotShowAlert) {
[tzImagePickerVc hideAlertView:alertView];
[self didGetAllPhotos:photos assets:assets infoArr:infoArr]; [self didGetAllPhotos:photos assets:assets infoArr:infoArr];
} }
} progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) { } progressHandler:^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
// 如果图片正在从iCloud同步中,提醒用户 // 如果图片正在从iCloud同步中,提醒用户
if (progress < 1 && havenotShowAlert) { if (progress < 1 && havenotShowAlert && !alertView) {
[tzImagePickerVc hideProgressHUD]; [tzImagePickerVc hideProgressHUD];
[tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]]; alertView = [tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]];
havenotShowAlert = NO; havenotShowAlert = NO;
return; return;
} }
if (progress >= 1) {
havenotShowAlert = YES;
}
} networkAccessAllowed:YES]; } networkAccessAllowed:YES];
} }
if (tzImagePickerVc.selectedModels.count <= 0) { if (tzImagePickerVc.selectedModels.count <= 0) {
......
...@@ -123,12 +123,18 @@ ...@@ -123,12 +123,18 @@
_model = model; _model = model;
[_scrollView setZoomScale:1.0 animated:NO]; [_scrollView setZoomScale:1.0 animated:NO];
if (model.type == TZAssetModelMediaTypePhotoGif) { if (model.type == TZAssetModelMediaTypePhotoGif) {
// 先显示缩略图
[[TZImageManager manager] getPhotoWithAsset:model.asset completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
self.imageView.image = photo;
[self resizeSubviews];
// 再显示gif动图
[[TZImageManager manager] getOriginalPhotoDataWithAsset:model.asset completion:^(NSData *data, NSDictionary *info, BOOL isDegraded) { [[TZImageManager manager] getOriginalPhotoDataWithAsset:model.asset completion:^(NSData *data, NSDictionary *info, BOOL isDegraded) {
if (!isDegraded) { if (!isDegraded) {
self.imageView.image = [UIImage sd_tz_animatedGIFWithData:data]; self.imageView.image = [UIImage sd_tz_animatedGIFWithData:data];
[self resizeSubviews]; [self resizeSubviews];
} }
}]; }];
} progressHandler:nil networkAccessAllowed:NO];
} else { } else {
self.asset = model.asset; self.asset = model.asset;
} }
...@@ -160,6 +166,11 @@ ...@@ -160,6 +166,11 @@
if (self.imageProgressUpdateBlock) { if (self.imageProgressUpdateBlock) {
self.imageProgressUpdateBlock(progress); self.imageProgressUpdateBlock(progress);
} }
if (progress >= 1) {
_progressView.hidden = YES;
self.imageRequestID = 0;
}
} networkAccessAllowed:YES]; } networkAccessAllowed:YES];
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
@property (nonatomic, strong) UIView *cropView; @property (nonatomic, strong) UIView *cropView;
@property (nonatomic, assign) double progress; @property (nonatomic, assign) double progress;
@property (strong, nonatomic) id alertView;
@end @end
@implementation TZPhotoPreviewController @implementation TZPhotoPreviewController
...@@ -283,7 +284,8 @@ ...@@ -283,7 +284,8 @@
TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController; TZImagePickerController *_tzImagePickerVc = (TZImagePickerController *)self.navigationController;
// 如果图片正在从iCloud同步中,提醒用户 // 如果图片正在从iCloud同步中,提醒用户
if (_progress > 0 && _progress < 1) { if (_progress > 0 && _progress < 1) {
[_tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]]; return; _alertView = [_tzImagePickerVc showAlertWithTitle:[NSBundle tz_localizedStringForKey:@"Synchronizing photos from iCloud"]];
return;
} }
// 如果没有选中过照片 点击确定时选中当前预览的照片 // 如果没有选中过照片 点击确定时选中当前预览的照片
...@@ -365,6 +367,12 @@ ...@@ -365,6 +367,12 @@
} }
[cell setImageProgressUpdateBlock:^(double progress) { [cell setImageProgressUpdateBlock:^(double progress) {
weakSelf.progress = progress; weakSelf.progress = progress;
if (progress >= 1) {
if (weakSelf.alertView) {
[_tzImagePickerVc hideAlertView:weakSelf.alertView];
[weakSelf doneButtonClick];
}
}
}]; }];
return cell; return cell;
} }
......
...@@ -466,6 +466,67 @@ ...@@ -466,6 +466,67 @@
[_collectionView reloadData]; [_collectionView reloadData];
} }
// Decide album show or not't
// 决定相册显示与否
- (BOOL)isAlbumCanSelect:(NSString *)albumName result:(id)result {
/*
if ([albumName isEqualToString:@"个人收藏"]) {
return NO;
}
if ([albumName isEqualToString:@"视频"]) {
return NO;
}*/
return YES;
}
// Decide asset show or not't
// 决定asset显示与否
- (BOOL)isAssetCanSelect:(id)asset {
/*
if (iOS8Later) {
PHAsset *phAsset = asset;
switch (phAsset.mediaType) {
case PHAssetMediaTypeVideo: {
// 视频时长
// NSTimeInterval duration = phAsset.duration;
return NO;
} break;
case PHAssetMediaTypeImage: {
// 图片尺寸
if (phAsset.pixelWidth > 3000 || phAsset.pixelHeight > 3000) {
// return NO;
}
return YES;
} break;
case PHAssetMediaTypeAudio:
return NO;
break;
case PHAssetMediaTypeUnknown:
return NO;
break;
default: break;
}
} else {
ALAsset *alAsset = asset;
NSString *alAssetType = [[alAsset valueForProperty:ALAssetPropertyType] stringValue];
if ([alAssetType isEqualToString:ALAssetTypeVideo]) {
// 视频时长
// NSTimeInterval duration = [[alAsset valueForProperty:ALAssetPropertyDuration] doubleValue];
return NO;
} else if ([alAssetType isEqualToString:ALAssetTypePhoto]) {
// 图片尺寸
CGSize imageSize = alAsset.defaultRepresentation.dimensions;
if (imageSize.width > 3000) {
// return NO;
}
return YES;
} else if ([alAssetType isEqualToString:ALAssetTypeUnknown]) {
return NO;
}
}*/
return YES;
}
#pragma mark - Click Event #pragma mark - Click Event
- (void)deleteBtnClik:(UIButton *)sender { - (void)deleteBtnClik:(UIButton *)sender {
......
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