菜鸟教程小白 发表于 2022-12-12 23:29:36

iphone - UIImagePickerController 选择多个图像


                                            <p><p>我正在尝试使用 UIImagePickerController 从照片库中选择多个图像,我希望可以在照片选择器底部添加一个 subview ,使其看起来像这个应用程序:</p>

<p>有简单的方法可以做到吗?我的代码目前只以标准方式弹出图像,但我只在加载 6 张图像时关闭 Controller </p>

<p><strong>重要的是,如果我可以向照片选择器 View 添加一个小 View /工具栏,就像示例中所做的那样,那么我可以完成剩下的工作</strong></p>

<p> <img src="/image/N9N2d.png" alt="Example Looking - With the custom toolbar in the bottom"/> </p>

<pre><code>    - (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType{
      //get all available source types
      NSArray *mediaTypes = ;

      //if source type available and supported media type is not null
      if ([UIImagePickerController isSourceTypeAvailable:sourceType
         &amp;&amp; &gt; 0]) {

      UIImagePickerController *picker = [ 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 **/

      ;
      } else {
      UIAlertView *alert = [ initWithTitle:@&#34;Error accessing media&#34;
                                                      message:@&#34;Device doesn&#39;t support that media type&#34;
                                                       delegate:nil
                                              cancelButtonTitle:@&#34;Drat !&#34;
                                              otherButtonTitles: nil];
      ;
      }
    }

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

      //if media type is image
      if () {
      UIImage *chosenImage = ;    //load image

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

      ; //add to image list
      imageNum++;
      }

      changeImageOrVideo = true;

      if(imageNum &gt;= 5){
          ;
      }
    }
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>使用诸如将 UIImagePickerController 向上移动并在下方显示所选图像之类的技巧的主要原因是, Assets 库替代方案会涉及到用户被要求访问位置,因为有关照片拍摄地点的信息在图像元数据中可用.</p>

<p>在 iOS 6 中,系统会询问用户是否要允许应用访问他们的照片(而不是位置),并且对于 Assets 库方法和 UIImagePickerController 方法都会询问您这个问题。</p>

<p>因此,我认为像上面这样的黑客已经接近了它们的用处。 <a href="https://github.com/w5mith/WSAssetPickerController" rel="noreferrer noopener nofollow">Here is a link to a library providing selection of multiple images using the Assets library</a>还有其他的。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - UIImagePickerController 选择多个图像,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/13093143/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/13093143/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - UIImagePickerController 选择多个图像