Commit ee8ed839 authored by banchichen's avatar banchichen

修复选择图片瞬间内存过高的问题

parent 1b577725
......@@ -20,7 +20,7 @@
@property (nonatomic, assign) BOOL shouldFixOrientation;
/// Default is 540px / 默认540像素宽
/// Default is 600px / 默认600像素宽
@property (nonatomic, assign) CGFloat photoPreviewMaxWidth;
/// Return YES if Authorized 返回YES如果得到了授权
......
......@@ -32,8 +32,8 @@ static CGFloat TZScreenScale;
TZScreenWidth = [UIScreen mainScreen].bounds.size.width;
// 测试发现,如果scale在plus真机上取到3.0,内存会增大特别多。故这里写死成2.0
TZScreenScale = 2.0;
if (TZScreenWidth > 600) {
TZScreenScale = 1.0;
if (TZScreenWidth > 700) {
TZScreenScale = 1.5;
}
CGFloat margin = 4;
CGFloat itemWH = (TZScreenWidth - 2 * margin - 4) / 4 - margin;
......@@ -336,7 +336,9 @@ static CGFloat TZScreenScale;
CGFloat pixelHeight = photoWidth / aspectRatio;
imageSize = CGSizeMake(pixelWidth, pixelHeight);
}
PHImageRequestID imageRequestID = [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init];
option.resizeMode = PHImageRequestOptionsResizeModeFast;
PHImageRequestID imageRequestID = [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:option resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]);
if (downloadFinined && result) {
result = [self fixOrientation:result];
......@@ -346,6 +348,7 @@ static CGFloat TZScreenScale;
if ([info objectForKey:PHImageResultIsInCloudKey] && !result) {
PHImageRequestOptions *option = [[PHImageRequestOptions alloc]init];
option.networkAccessAllowed = YES;
option.resizeMode = PHImageRequestOptionsResizeModeFast;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
UIImage *resultImage = [UIImage imageWithData:imageData scale:0.1];
resultImage = [self scaleImage:resultImage toSize:imageSize];
......
......@@ -37,7 +37,7 @@
/// Default is 828px / 默认828像素宽
@property (nonatomic, assign) CGFloat photoWidth;
/// Default is 520px / 默认540像素宽
/// Default is 600px / 默认600像素宽
@property (nonatomic, assign) CGFloat photoPreviewMaxWidth;
/// Default is 15, While fetching photo, HUD will dismiss automatic if timeout;
......
......@@ -88,7 +88,7 @@
self.allowTakePicture = YES;
self.timeout = 15;
self.photoWidth = 828.0;
self.photoPreviewMaxWidth = 540;
self.photoPreviewMaxWidth = 600;
if (![[TZImageManager manager] authorizationStatusAuthorized]) {
_tipLable = [[UILabel alloc] init];
......@@ -120,7 +120,7 @@
self.timeout = 15;
self.photoWidth = 828.0;
self.maxImagesCount = selectedAssets.count;
self.photoPreviewMaxWidth = 540;
self.photoPreviewMaxWidth = 600;
previewVc.photos = [NSMutableArray arrayWithArray:selectedPhotos];
previewVc.currentIndex = index;
......
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