UIImagePickerController选择多个图像 [英] UIImagePickerController Pick Multiple images

查看:189
本文介绍了UIImagePickerController选择多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图简单地使用UIImagePickerController从photolibrary中选择多个图像,我希望我可以在照片选择器的底部添加一个子视图,使它看起来像这个应用程序:

I am trying to simply enable picking multiple images from photolibrary using the UIImagePickerController, I wish I can add a subview on bottom of the photo picker so it look something like this app does:

有一种简单的方法可以做到吗?我的代码目前只以标准方式弹出图像,但我只在加载6张图像时关闭控制器

It there a simple way you can do it? My code currently only pops the images in a standard way but I only dismiss the controller when loaded 6 images

重要的是,如果我还是可以添加一个照片选择器视图的小视图/工具栏,就像示例一样,我可以完成剩下的工作

    - (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType{
      //get all available source types
      NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];

      //if source type available and supported media type is not null
      if ([UIImagePickerController isSourceTypeAvailable:sourceType
           && [mediaTypes count] > 0]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        //picker.mediaTypes = mediaTypes;   //allow videos
        picker.delegate = self;
        picker.sourceType = sourceType; //set source type to the given type

        /** WANT TO ADD A CUSTOM VIEW IN THE PHOTO PICKER VIEW **/

        [self presentViewController:picker animated:YES completion:nil];
      } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing media"
                                                        message:@"Device doesn't support that media type"
                                                       delegate:nil
                                              cancelButtonTitle:@"Drat !"
                                              otherButtonTitles: nil];
        [alert show];
      }
    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
      self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType];  //record media type

      //if media type is image
      if ([lastChosenMediaType isEqual:(NSString *) kUTTypeImage]) {
        UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];    //load image

        //save the image if is from camera shot
        if (imageOrVideoSourceType == UIImagePickerControllerSourceTypeCamera) {
          UIImageWriteToSavedPhotosAlbum (chosenImage, nil, nil , nil);
        }

        [images addObject:chosenImage]; //add to image list
        imageNum++;
      }

      changeImageOrVideo = true;

      if(imageNum >= 5){
          [picker dismissViewControllerAnimated:YES completion:nil];
      }
    }


推荐答案

使用黑客攻击的主要原因,如移动UIImagePickerController并显示下面的选定图像是因为资产库替代方案将涉及要求用户进行位置访问,因为有关照片拍摄位置的信息在图像元数据中可用。

The main reason for using hacks like shifting the UIImagePickerController up and showing selected images underneath was because the asset library alternative would involve the user being asked for location access due to the information about where the photo was taken being available in the image metadata.

在iOS 6中,系统会询问用户是否允许应用访问他们的照片(而非位置),并且您会收到有关资产库方法和UIImagePickerController方法的问题。

In iOS 6 the user is asked if they want to allow the app to access their photos (not location) and you get asked this question for both the asset library approach and the UIImagePickerController approach.

因此我认为像上面这样的黑客已接近它们的实用性。 这是指向使用资产库提供多个图像选择的库的链接还有其他。

As such I think that hacks like the above are nearing the end of their usefulness. Here is a link to a library providing selection of multiple images using the Assets library there are others.

这篇关于UIImagePickerController选择多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆