UIImagePickerController编辑的图像在iPad中检索错误的图像

时间:2017-03-27 13:20:21

标签: ios swift ipad uiimage uiimagepickercontroller

我有UIImagePickerController从照片库中选择/选择图片。我已经允许UIImagePickerController编辑(选中)图像(裁剪图像的方框),这适用于iPhone,但iPad无法提供正确的编辑(裁剪)图像。

我尝试了以下建议但找不到解决方案:
iPad iOS7 - UIImagePickerController in UIPopoverController has wrong preview image

以下是我尝试过的代码:

let imagePicker = UIImagePickerController()
imagePicker.allowsEditing = true

// Update (zoom) visibility of image using pinch gesture & retrieve image using delegate - didFinishPickingMediaWithInfo

//------------------------------------------
 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {


     if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
         // Wrong image - retrieves image different than actual visible in editing window of picker view.
    }


    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        // Original image, visible perfect in iPad, when imagePicker.allowsEditing = false
    }


    picker.dismiss(animated: true) {
        // dismissing image picker
    }

}

1 个答案:

答案 0 :(得分:2)

添加此方法,您将获得准确的结果。

func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
    UIApplication.shared.isStatusBarHidden = true
}