简体   繁体   English

UIImagePickerController选择多个图像

[英]UIImagePickerController Pick Multiple images

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: 我试图简单地启用使用UIImagePickerController从照相馆中拾取多个图像,希望我可以在照片选择器的底部添加一个子视图,以便它看起来像此应用程序一样:

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 我的代码当前仅以标准方式弹出图像,但仅在加载6张图像时关闭控制器

The important thing there is if anyway I can add a small view/toolbar to the photo picker view, like the example did, I then can do the rest 重要的是,如果我可以像示例一样向照片选择器视图添加一个小视图/工具栏,那么我就可以完成其余工作

查找示例-底部的自定义工具栏

    - (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];
      }
    }

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. 使用黑客之类的主要原因,例如将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. 在iOS 6中,系统询问用户是否要允许该应用访问其照片(而不是位置),并且对于资源库方法和UIImagePickerController方法,系统都会询问您此问题。

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. 这是一个到库的链接,该库提供使用Assets库选择多个图像的选择,还有其他图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM