android ios 相册图片多选,ios 选择系统相册多张图片功能

CTAssetsPickerController通过它来实现pod 'CTAssetsPickerController',  '~> 3.3.0'

导入文件之后,在你需要用到的页面记得引入头文件

#import #import签协议CTAssetsPickerControllerDelegate

-(void)saveAction{

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

if (status != PHAuthorizationStatusAuthorized) return ;

dispatch_async(dispatch_get_main_queue(), ^{

//弹出控制器

CTAssetsPickerController *assetPC = [[CTAssetsPickerController alloc] init];

//隐藏空相册

assetPC.showsEmptyAlbums=YES;

//显示图片索引

assetPC.showsSelectionIndex=YES;

//显示那些资源

assetPC.assetCollectionSubtypes = @[@(PHAssetCollectionSubtypeSmartAlbumUserLibrary), @(PHAssetCollectionSubtypeAlbumRegular)];

assetPC.delegate=self;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //如果是运行到ipad上面

{

assetPC.modalPresentationStyle = UIModalPresentationFormSheet;

}

[self presentViewController:assetPC animated:YES completion:nil];

});

}];

}

#pragma mark - CTAssetsPickerControllerDelegate -

// 限定选择的最大选择个数

- (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset{

NSIntegermaxNumber =9;

if(picker.selectedAssets.countreturnYES;

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"最多选择%ld张", (long)maxNumber] preferredStyle:UIAlertControllerStyleAlert];

[alertaddAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];

[pickerpresentViewController:alert animated:YES completion:nil];

return NO;

}

- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets{

//选择完毕关闭页面

[pickerdismissViewControllerAnimated:YES completion:nil];

PHImageRequestOptions *option = [[PHImageRequestOptions alloc] init];

option.resizeMode=  PHImageRequestOptionsResizeModeExact;

option.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

//生成图片

for(inti =0; i < assets.count; i++){

NSLog(@"%@",[NSThread currentThread]);

PHAsset*asset = assets[i];

CGSize asseSize = CGSizeMake(asset.pixelWidth / [UIScreen mainScreen].scale, asset.pixelHeight / [UIScreen mainScreen].scale);

[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:asseSize contentMode:PHImageContentModeDefault options:option 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);

//分享到微信好友、朋友圈、收藏,这三个场景是不支持多张图片的,用微信sdk来实现的话,只能是一张

//            WXImageObject *imgObj = [WXImageObject object];

//            NSData *imagedata = UIImagePNGRepresentation(result);

//            imgObj.imageData = imagedata;

//

//            WXMediaMessage *message =[WXMediaMessage message];

//            message.mediaObject = imgObj;

//            SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];

//            req.bText = NO;

//            req.message = message;

//            req.scene = WXSceneFavorite;

//            [WXApi sendReq:req completion:nil];

}];

}

}

当你选好几张图片之后,选择分享到朋友圈时,默认就是选择一张

7dfe42585fb5

7dfe42585fb5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值