0

我正在展示一张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) 

如果有人有其他替代解决吧!

+0

你怎么解雇'UIImagePickerController'? – Poles

+0

@Poles当然,编辑后显示它 – Makaille

+0

你确定你的类是图像选择器所需的UINavigationControllerDelegate的子类吗? – pbush25

回答

0

使用picker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext在呈现imagepicker之前。

+0

这使得我的视图完全没了,每个按钮都不起作用,并且不显示选取器。 – Makaille

+0

好的。使用'imagePicker.parent?.dismiss(animated:true,completion:nil)',同时关闭imagepicker。 – Poles

+0

问题不在于选取器,我在应用程序中进行了调查,并且始终使用现有方法。这就像现在和导航控制器之间的冲突 – Makaille

0

下面是我用相机代码:

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

0

设置.modalPresentationStyle为全屏

+0

的呼叫礼物方法已经提出,不起作用 – Makaille