iOS从系统相册选取多张照片示例代码
2017-03-01 14:08
851 查看
之前写过UIImagePickerController调取系统相册图片(选取单张照片,多用于用户头像)
1.pod导入
pod 'CTAssetsPickerController'
2.添加头文件
#import <CTAssetsPickerController/CTAssetsPickerController.h>
3.添加delegate
<CTAssetsPickerControllerDelegate>
4.实现
- (void)upLoading { [PHPhotoLibraryrequestAuthorization:^(PHAuthorizationStatus status){ if (status !=PHAuthorizationStatusAuthorized)return; dispatch_async(dispatch_get_main_queue(), ^{ CTAssetsPickerController *picker = [[CTAssetsPickerControlleralloc] init]; picker.delegate =self; // 显示选择的索引 picker.showsSelectionIndex =YES; // 设置相册的类型:相机胶卷 +自定义相册 picker.assetCollectionSubtypes =@[ @(PHAssetCollectionSubtypeSmartAlbumUserLibrary), @(PHAssetCollectionSubtypeAlbumRegular)]; // 不需要显示空的相册 picker.showsEmptyAlbums =NO; [selfpresentViewController:pickeranimated:YEScompletion:nil]; }); }]; } -(BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset { NSInteger max =9; if (picker.selectedAssets.count >= max) { UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"提示"message:[NSStringstringWithFormat:@"最多选择%zd张图片", max] preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertActionactionWithTitle:@"好的"style:UIAlertActionStyleDefaulthandler:nil]]; [picker presentViewController:alertanimated:YEScompletion:nil]; // 这里不能使用self来modal别的控制器,因为此时self.view不在window上 returnNO; } returnYES; } -(void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets { NSArray *array =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); NSString *documents = [arraylastObject]; NSString *documentPath = [documentsstringByAppendingPathComponent:@"arrayXML.xml"]; NSArray *dataArray = [NSArrayarrayWithArray:assets]; [dataArray writeToFile:documentPathatomically:YES]; NSArray *resultArray = [NSArrayarrayWithContentsOfFile:documentPath]; NSLog(@"%@", documentPath); // 关闭图片选择界面 [picker dismissViewControllerAnimated:YEScompletion:nil]; // 遍历选择的所有图片 self.plCollection.photoArray = assets; for (NSInteger i =0; i < assets.count; i++) { // 基本配置 CGFloat scale = [UIScreenmainScreen].scale; PHImageRequestOptions *options = [[PHImageRequestOptionsalloc] init]; options.resizeMode =PHImageRequestOptionsResizeModeExact; options.deliveryMode =PHImageRequestOptionsDeliveryModeHighQualityFormat; PHAsset *asset = assets[i]; CGSize size =CGSizeMake(asset.pixelWidth / scale, asset.pixelHeight / scale); // // 获取图片 [[PHImageManagerdefaultManager] requestImageForAsset:assettargetSize:size contentMode:PHImageContentModeDefaultoptions:options resultHandler:^(UIImage *_Nullable result,NSDictionary *_Nullable info) { NSData *imageData =UIImageJPEGRepresentation([selfimageWithImageSimple:resultscaledToSize:CGSizeMake(200,200)], 0.5); [selfossUpload:imageData]; }]; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- IOS获取系统相册中照片的示例代码
- iOS开发-调用系统相机和相册获取照片示例
- iOS之保存图片到系统相册和从系统相册选取一张或者多张照片
- IOS - 使用 QBImagePickerController 从系统相册选取多张照片
- iOS判断从系统相册选取的是视频还是照片
- iOS从系统相册选取多张照片
- Android开发从相册中选取照片的示例代码
- iOS开发之保存照片到系统相册(Photo Album)
- 解决iOS8.0以上系统下无法通过代码创建被删除过的同名相册 ( iOS 8 Photos framework: Create a albums with iOS8 )
- iOS开发系统相册的选取
- iOS 获取系统相册全部照片以及照片信息
- ios:从系统相册选取视频并获得视频的缩略图
- iOS 调用系统相机和选择相册照片
- iOS 调用系统相册,调用系统照相机,调用系统相册,并且对照片进行剪裁
- iOS开发之保存照片到系统相册(Photo Album)
- iOS保存系统相册中的照片到应用沙盒中出现的问题--图片旋转90度,使用CGImageRelease造成应用崩溃
- android 调用系统相册选取照片或者打开相机拍照获取图片,返回时为什么会回到home界面或者到前一个界面,然后才会跳转到当前activity
- iOS - 获取系统相册照片名称,路径以及各项信息
- ios 调用系统相机,图库,相册。将照片保存在相册,保存图片在本地,UIImagePickerController