#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. // photo image picker asset
} - (IBAction)selectPhoto { [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
if (status != PHAuthorizationStatusAuthorized) return; dispatch_async(dispatch_get_main_queue(), ^{
// 弹出图片选择界面
CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
// 隐藏空相册
picker.showsEmptyAlbums = NO;
// 显示图片索引
picker.showsSelectionIndex = YES;
picker.assetCollectionSubtypes = @[
@(PHAssetCollectionSubtypeSmartAlbumUserLibrary),
@(PHAssetCollectionSubtypeAlbumRegular)
];
picker.delegate = self; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // 如果当前运行的设备是平板电脑
picker.modalPresentationStyle = UIModalPresentationFormSheet;
} [self presentViewController:picker animated:YES completion:nil];
});
}];
} #pragma mark - <CTAssetsPickerControllerDelegate>
- (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset
{
NSInteger max = 9; if (picker.selectedAssets.count < max) return YES; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注意"
message:[NSString stringWithFormat:@"最多选择%zd张图片", max]
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil]];
// 这里一定要用picker,不能使用self(因为当前显示在上面的控制器是picker,不是self)
[picker presentViewController:alert animated:YES completion:nil]; return NO;
} /**
* 选择完毕的时候调用
*/
- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
// 关闭图片选择界面
[picker dismissViewControllerAnimated:YES completion:nil]; // 选择图片时的配置项
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.resizeMode = PHImageRequestOptionsResizeModeExact;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; // 显示图片
for (NSInteger i = 0; i < assets.count; i++) {
PHAsset *asset = assets[i];
CGSize size = CGSizeMake(asset.pixelWidth / [UIScreen mainScreen].scale, asset.pixelHeight / [UIScreen mainScreen].scale); // 请求图片
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
// 添加图片控件
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = result;
[self.view addSubview:imageView]; imageView.frame = CGRectMake((i % 3) * (100 + 10), (i / 3) * (100 + 10), 100, 100);
}];
}
}
@end

ios---选择多张图片的更多相关文章

  1. html5 选择多张图片在页面内预览并上传到后台

    版权声明:本文为博主原创文章,未经博主允许不得转载. http://blog.csdn.net/huangxin112/article/details/74956462 需求:点击选择图片(可选多张) ...

  2. 利用WebUploader进行图片批量上传,在页面显示后选择多张图片压缩至指定路径【java】

    WebUploader是由Baidu WebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件.在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览 ...

  3. js移动端/H5同时选择多张图片上传并使用canvas压缩图片

    最近在做一个H5的项目,里边涉及到拍照上传图片的功能以及识别图片的功能,这里对识别图片的功能不做赘述,不属本文范畴.我在做完并上线项目后,同事跟我提了一个要求是可不可以同时选择多张图片上传,我做的时候 ...

  4. Cordova各个插件使用介绍系列(三)—$cordovaImagePicker从手机图库选择多张图片

    详情链接地址:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/cordova-3-cordovaimagepicker/ 这是能从手 ...

  5. js-jssdk微信H5选择多张图片预览并上传(兼容ios,安卓,已测试)

    值得注意的是: 1.在微信H5中选择图片运用:wx.chooseImage,成功后返回:  res.localIds用于上传图片使用    上传图片:wx.uploadImage. 2.上传图片的时候 ...

  6. IOS 选择会员资格

    选择会员资格 针对所有 Apple 平台进行开发从未如此简单.要开始为 macOS.iOS.tvOS 和 watchOS 开发 app,请从 Mac App Store 下载 Xcode.如果您已准备 ...

  7. iOS选择相片优化

    1.问题 在ios中有时需要选择本地图片或者拍照,有时候选择相片的时候会有多选和单选,所以需要首先封装相册选择,在之前的博客中也有写到IOS多选单选相册图片.这个只是对相册中选择图片的封装.我们在ap ...

  8. iOS 选择的照片或者拍照的图片上添加日期水印

    1..引入框架 #import "CLLocation+GPSDictionary.h"#import "NSDictionary+CLLocation.h" ...

  9. plupload 限制上传数量 只能选择一张图片上传

    var files=[];var errors=[];            var chunk=<%=request.getParameter("chunk")%>; ...

  10. iOS把两张图片合成一张图片

    0x00 步骤 先读取两张图片把创建出CGImageRef 创建上下文画布 把图片依次画在画布指定位置上 从上下文中获得合并后的图片 关闭上下文 释放内存 0x01 代码实现 - (void)comp ...

随机推荐

  1. 安卓中运行报错Error:Execution failed for task ':app:transformClassesWithDexForDebug'解决

    在androidstuio中运行我的未完项目,报错: Error:Execution failed for task ':app:transformClassesWithDexForDebug'.&g ...

  2. Kafka学习笔记(四)—— API使用

    Kafka学习笔记(四)-- API使用 1.Producer API 1.1 消息发送流程 Kafka的Producer发送消息采用的是异步发送的方式.在消息发送的过程中,涉及到了两个线程--mai ...

  3. 不仅仅是双11大屏—Flink应用场景介绍

    双11大屏 每年天猫双十一购物节,都会有一块巨大的实时作战大屏,展现当前的销售情况. 这种炫酷的页面背后,其实有着非常强大的技术支撑,而这种场景其实就是实时报表分析. 实时报表分析是近年来很多公司采用 ...

  4. Prometheus + Grafana 部署说明之「安装」

    说明 在前面的Prometheus学习系列文章里,大致介绍说明了Prometheus和Grafana的一些使用,现在开始介绍如何从头开始部署Prometheus+Grafana,来监控各个相关的指标数 ...

  5. DM7的SQL批量插入for、while方法

    示例1,for用法: begin for i in 1...10000 loop insert into test values(i,i,'aaa',sysdate); if i mod 20 = 0 ...

  6. 突破CRUD | 简单优雅的代码生成工具诞生记(万字长文慎入)

    0.学习本文你或许可以收获 1.一个需求从产生.分析到解决的全过程思考2.简单的面向对象分析实践3.UML类图实践4.设计模式的实践应用5.最后收获一款还算不错的代码生成工具实现思路和源代码 本文将从 ...

  7. 深度学习论文翻译解析(六):MobileNets:Efficient Convolutional Neural Networks for Mobile Vision Appliications

    论文标题:MobileNets:Efficient Convolutional Neural Networks for Mobile Vision Appliications 论文作者:Andrew ...

  8. oracle官网下载jdk跑不动太慢了,给出快速下载方式mac

    oracle官网下载jdk8跑不动太慢了,给出快速下载方式 之前在oracle官网下载jdk1.8实在速度太慢,只有20K左右的下载速度,有时候甚至不动,最关键的慢也就算了,cookie有效期有限,有 ...

  9. Spark学习笔记(四)—— Yarn模式

    1.Yarn运行模式介绍 Yarn运行模式就是说Spark客户端直接连接Yarn,不需要额外构建Spark集群.如果Yarn是分布式部署的,那么Spark就跟随它形成了分布式部署的效果.有yarn-c ...

  10. Intellij Idea插件使用记录之Alibaba Java Coding Guidelines

    目录 Intellij Idea插件Alibaba Java Coding Guidelines 前言 使用 感谢 Intellij Idea插件Alibaba Java Coding Guideli ...