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