image_picker:取消按钮在图库中不可见,如果首先访问相机

image_picker: Cancel button not visible in gallery, if camera was accessed first

这就是我在 flutter 应用程序中打开图库和相机的方式。问题是,我先启动相机,然后在打开图库后,导航栏顶部缺少取消按钮和标题。

但是如果退出并重新启动应用程序并且我首先打开了图库,我可以在 ios 图片选择器中看到标题和取消按钮。

File img = await ImagePicker.pickImage(source: ImageSource.gallery);

您可以使用这个图像选择器插件:- https://pub.dartlang.org/packages/multi_image_picker#-readme-tab-

本插件在原图片选择器插件的基础上增加了更多功能。

我在申请中遇到了同样的问题。我的解决方案是:

var imagePicker: UIImagePickerController?

func openCamera() -> Void {
    if UIImagePickerController.isSourceTypeAvailable(.camera) {
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.sourceType = .camera;
        picker.allowsEditing = false
        imagePicker = picker //made this way to avoid forced unwrapping in imagePicker
        self.present(picker, animated: true, completion: nil)
    }
}

func openLibrary() -> Void {
    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.sourceType = .photoLibrary;
        picker.allowsEditing = true
        imagePicker = picker
        self.present(picker, animated: true, completion: nil)
    }
}

然后我不得不实施这个:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    imagePicker?.dismiss(animated: true, completion: nil)

    uploadImage(resizeImage) //my function to upload the selected image
    imagePicker = nil
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    imagePicker?.dismiss(animated: true, completion: nil)
    imagePicker = nil
}

应用于Swift 4.2

的解决方案