【问题标题】:How can I tell if the image returned from didFinishPickingMediaWithInfo was from the camera or the photoalbum?如何判断从 didFinishPickingMediaWithInfo 返回的图像是来自相机还是相册?
【发布时间】:2011-08-23 01:12:32
【问题描述】:

我有一个视图控制器,它需要能够从相册和相机中选择图片。对于 didFinishPickingMediaWithInfo 我只能有 1 个委托方法,虽然我可以判断它是否是图像,但我似乎无法判断它是来自相册还是来自相机(我需要先将其保存在相册中)。信息中有什么可以帮助我区分这两者的吗?

谢谢...

【问题讨论】:

    标签: uiimagepickercontroller


    【解决方案1】:

    因为UIImagePickerController是传递给方法的,所以你要做的就是:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
      if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
        // Do something with an image from the camera
      } else {
        // Do something with an image from another source
      }
    }
    

    【讨论】:

      【解决方案2】:

      在 Swift3 中:

      func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
      
          if picker.sourceType == .camera {
            // Do something with an image from the camera
          }
          else {
            // Do something with an image from another source
          }
      
        }
      

      【讨论】:

      • 在 Swift 3.0 中,它现在是 picker.sourceType == .camera,因为 .Camera 已被 .camera 取代。其他值为.photoLibrary.savedPhotosAlbum。 HTH
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多