简体   繁体   English

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

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

This is how open gallery and camera in my flutter application. 这就是在我的抖动应用程序中如何打开画廊和照相机。 The problem is, I launch camera first then after I open gallery I'm missing cancel button and title on the top in the navigation bar. 问题是,我先启动相机,然后打开图库后,我在导航栏中没有找到取消按钮和标题。

But if exit and relaunch the app and I opened gallery first, I can see the title and cancel button in ios image picker. 但是,如果退出并重新启动该应用程序,然后我首先打开图库,则可以在ios图像选择器中看到标题和取消按钮。

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

You can use this image picker plugin :- https://pub.dartlang.org/packages/multi_image_picker#-readme-tab- 您可以使用此图像选择器插件:-https: //pub.dartlang.org/packages/multi_image_picker#-readme-tab-

This plugin is based on the original image picker plugin with more features. 该插件基于具有更多功能的原始图像选择器插件。

I faced same problem in my application. 我在应用程序中遇到了同样的问题。 My solution was: 我的解决方案是:

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)
    }
}

and then I had to implement this: 然后我必须实现这一点:

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
}

Solution applied to Swift 4.2 解决方案应用于Swift 4.2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter Image_Picker 在打开相机时崩溃 iOS 应用程序 - Flutter Image_Picker crash iOS app when open Camera 从图库中选择图像时,image_picker 使应用程序崩溃 IOS,控制台中没有任何日志 - While picking an image from gallery, image_picker is crashing the the app on IOS with no logs in the console 颤振:“与设备的连接丢失。” 第二次使用 image_picker 从 iOS 上的图库中选择照片 - Flutter: 'Lost connection to device.' second time using image_picker to select photo from gallery on iOS Flutter image_picker 视频库 OSError: Operation not allowed [Errno 1] IOS 13 - Flutter image_picker video gallery OSError: Operation not permitted [Errno 1] IOS 13 日期/时间选择器颤动:确定/取消按钮不可见 - Date/Time Picker Flutter : OK/CANCEL button not visible 相机/图库按钮在一个场景中,图像在另一个场景中 - Camera/Gallery Button in One scene, Image in Another MFMailComposeViewController:取消按钮不可见 - MFMailComposeViewController: Cancel button is not visible 如何解决在 Xcode 上找不到模块“image_picker”的问题? - How to solve this problem Module 'image_picker' not found on Xcode? Ionic v1 - 本机日期选择器的视图仅在 iPhone 7 中不可见(带有取消和 Select 按钮的白屏)? - Ionic v1 - Native Date Picker's view is not visible(white Screen with Cancel & Select button) in iPhone 7 only? 如何使用相机按钮将图像选择器添加到iOS应用 - How to add image picker with camera button to iOS app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM