出现UIImagePickerController后的白色屏幕
问题描述:
我正在展示一张UIImagePickerController
拍照,问题是如果我拍照或取消UIImagePickerController
我会在白色屏幕上返回,而不是我之前的ViewController
。只有我的navigation bar
还在这里。如果我点击另一个view
(使用导航栏),这没关系,如果我返回的标签UIImagePickerController
被称为它仍然是白色的。出现UIImagePickerController后的白色屏幕
let picker = UIImagePickerController();
picker.delegate = self;
picker.mediaTypes = [swiftString];
picker.allowsEditing = true
picker.sourceType = UIImagePickerControllerSourceType.camera;
picker.cameraCaptureMode = .photo
self.present(picker, animated:true, completion:nil);
解雇:
picker.dismiss(animated: true, completion:nil);
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion:nil);
}
如果有人有一个想法,感谢的!
更新:当我打电话与present method
视图
白色屏幕始终显示。所以我认为这是一个与导航控制器冲突(层次...)
这解决我的问题:
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {return}
appDelegate.navigationController.present(picker, animated: true, completion: nil)
如果有人有其他替代解决吧!
答
下面是我用相机代码:
func openCameraApp() {
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
picker.allowsEditing = false
picker.sourceType = UIImagePickerControllerSourceType.camera
picker.cameraCaptureMode = .photo
picker.modalPresentationStyle = .fullScreen
present(picker,
animated: true,
completion: nil)
} else {
noCamera()
}
}
func noCamera(){
let alertVC = UIAlertController(
title: "No Camera",
message: "Sorry, this device has no camera",
preferredStyle: .alert)
let okAction = UIAlertAction(
title: "OK",
style:.default,
handler: nil)
alertVC.addAction(okAction)
present(
alertVC,
animated: true,
completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage // do you have this line in your code?
image = chosenImage
self.performSegue(withIdentifier: "ShowEditView", sender: self)
dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: false, completion: nil)
}
我看到一对夫妇的事情不同。
- 您将
.allowsEditing
设置为true。我不相信这是有所作为的。 - 我正在检查相机,但您可能没有在您的问题中提供该代码。
- 我将
.modalPresentationStyle
设置为全屏。这可能是你的问题。 - 我没有看到
imagePickerController(picker: didFinishPickingMediaWithInfo)
呼叫。但由于它不应该建立,这肯定不是问题。 - 在那个电话里面,我打开
info
的图像。 我相信这是你的问题。我已对该特定行发表了评论,要求您检查此内容。 - 最后,我正在执行一个segue到另一个视图控制器。 (我的应用程序基本上是“选择”,然后“编辑”。)
+0
您好,感谢您的帮助,但它没有改变。我会更新帖子,问题来自我的导航控制器 – Makaille
你怎么解雇'UIImagePickerController'? – Poles
@Poles当然,编辑后显示它 – Makaille
你确定你的类是图像选择器所需的UINavigationControllerDelegate的子类吗? – pbush25