這篇文章將為大家詳細(xì)講解有關(guān)怎么在iOS中實(shí)現(xiàn)從系統(tǒng)相冊(cè)選取多張照片,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
為嘉陵等地區(qū)用戶(hù)提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及嘉陵網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為做網(wǎng)站、網(wǎng)站設(shè)計(jì)、嘉陵網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶(hù)提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶(hù)的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
1.pod導(dǎo)入
pod 'CTAssetsPickerController'
2.添加頭文件
#import
3.添加delegate
4.實(shí)現(xiàn)
- (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; // 設(shè)置相冊(cè)的類(lèi)型:相機(jī)膠卷 +自定義相冊(cè) picker.assetCollectionSubtypes =@[ @(PHAssetCollectionSubtypeSmartAlbumUserLibrary), @(PHAssetCollectionSubtypeAlbumRegular)]; // 不需要顯示空的相冊(cè) 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來(lái)modal別的控制器,因?yàn)榇藭r(shí)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); // 關(guān)閉圖片選擇界面 [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]; }]; } }
關(guān)于怎么在iOS中實(shí)現(xiàn)從系統(tǒng)相冊(cè)選取多張照片就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。