-2

在我的应用程序中,我希望该用户应该能够从他的图库中选择多个图像,但是使用 UIImagePickerController 我们一次只能选择 1 个图像。由于我是新手,对 Objective-c 了解不多,我无法实现 GitHub 上可用的多图像选择器组件,例如 MAImagePicker、QBImagePicker、ELCImagePickerController。

如果有人使用过这些组件中的任何一个,请向我提供示例代码和实现该组件的步骤。

4

1 回答 1

5

使用 ELCImagePicker https://github.com/B-Sides/ELCImagePickerController

从 github 下载并导入您的项目。

添加选择图像按钮

- (IBAction)selectImg:(id)sender
{
    ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
    elcPicker.maximumImagesCount = 100; //Set the maximum number of images to select to 100
    elcPicker.returnsOriginalImage = YES; //Only return the fullScreenImage, not the fullResolutionImage
    elcPicker.returnsImage = YES; //Return UIimage if YES. If NO, only return asset location information
    elcPicker.onOrder = YES; //For multiple image selection, display and return order of selected images
    elcPicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie]; //Supports image and movie types
    elcPicker.imagePickerDelegate = self;
    [self presentViewController:elcPicker animated:YES completion:nil];
}

从此方法获取图像。

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];

    for (NSDictionary *dict in info)
    {
        if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypePhoto)
        {
            if ([dict objectForKey:UIImagePickerControllerOriginalImage])
            {
                UIImage* image=[dict objectForKey:UIImagePickerControllerOriginalImage];
                [arrImgs addObject:image];
            }
        }
    }

}

- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
于 2016-06-07T09:13:24.363 回答