ZZBrowserPickerCell.m
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// ZZBrowserPickerCell.m
// ZZFramework
//
// Created by Yuan on 15/12/23.
// Copyright © 2015年 zzl. All rights reserved.
//
#import "ZZBrowserPickerCell.h"
#import "UIImageHandle.h"
@implementation ZZBrowserPickerCell
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_pics = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
_pics.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:_pics];
}
return self;
}
-(void)loadPHAssetItemForPics:(PHAsset *)assetItem
{
PHAsset *phAsset = (PHAsset *)assetItem;
CGFloat photoWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat aspectRatio = phAsset.pixelWidth / (CGFloat)phAsset.pixelHeight;
CGFloat multiple = [UIScreen mainScreen].scale;
CGFloat pixelWidth = photoWidth * multiple;
CGFloat pixelHeight = pixelWidth / aspectRatio;
[[PHImageManager defaultManager] requestImageForAsset:phAsset targetSize:CGSizeMake(pixelWidth, pixelHeight) contentMode:PHImageContentModeAspectFit options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
BOOL downloadFinined = ![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey] && ![[info objectForKey:PHImageResultIsDegradedKey] boolValue];
//设置BOOL判断,确定返回高清照片
if (downloadFinined) {
self.pics.image = result;
}
}];
}
@end