[英]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.