#import "ViewController.h"
#import <CTAssetsPickerController.h>
@interface ViewController () <CTAssetsPickerControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// label.text = NSLocalizedStringFromTable(@"Name", @"Test", nil);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
dispatch_async(dispatch_get_main_queue(), ^{
CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
picker.delegate = self;
picker.assetCollectionSubtypes =
@[@(PHAssetCollectionSubtypeSmartAlbumUserLibrary),
@(PHAssetCollectionSubtypeAlbumRegular)];
[self presentViewController:picker animated:YES completion:nil];
});
}];
}
#pragma mark - <CTAssetsPickerControllerDelegate>
- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
// 关闭图片选择界面
[picker dismissViewControllerAnimated:YES completion:nil];
// 取出所有选择的图片
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeExact;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
PHImageManager *manager = [PHImageManager defaultManager];
NSInteger index = 0;
for (PHAsset *asset in assets) {
[manager requestImageForAsset:asset
targetSize:CGSizeMake(100, 100)
contentMode:PHImageContentModeAspectFill
options:requestOptions
resultHandler:^(UIImage *image, NSDictionary *info){
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = image;
imageView.frame = CGRectMake(110 * (index % 3), 110 * (index / 3), 100, 100);
[self.view addSubview:imageView];
}];
index++;
}
}
@end
photo
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- [作者前言] 伟大的法国雕塑艺术家罗丹曾经说过:“美是到处都有的。对于我们的眼睛,不是缺少美,而是缺少发现。” ...
- ios8 以及之后使用了photo framework这个新的框架,也就是,如果我们在xcode8 上进行使用的时...
- 我之前也回答过这样一个问题,说当身体出现什么信号就不能在饮酒了,很多人回答说当酒量突然增加或下降,消化不良脾胃不好...