怎么在iOS中实现从系统相册选取多张照片
这篇文章将为大家详细讲解有关怎么在iOS中实现从系统相册选取多张照片,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
为嘉陵等地区用户提供了全套网页设计制作服务,及嘉陵网站建设行业解决方案。主营业务为做网站、网站设计、嘉陵网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
1.pod导入
pod 'CTAssetsPickerController'
2.添加头文件
#import
3.添加delegate
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中实现从系统相册选取多张照片
转载来源:http://scyanting.com/article/jspiph.html