image_picker:如果首先访问相机,则在图库中看不到“取消”按钮

时间:2018-10-26 10:53:24

标签: ios flutter uiimagepickercontroller uiimagepickercontrollermediatype

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

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

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

2 个答案:

答案 0 :(得分:1)

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

此插件基于具有更多功能的原始图像选择器插件。

答案 1 :(得分:-1)

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

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