我正在展示UIImagePickerController
来拍照,问题是如果我拍照,或取消UIImagePickerController
我会在白色屏幕上返回,而不是在我之前的{{ 1}}。只有我的ViewController
仍然在这里。如果我点击其他navigation bar
(使用导航栏)就可以了,如果我返回调用view
的标签,它仍然是白色的。
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
如果有人有其他选择来解决它!
答案 0 :(得分:0)
在展示图片选择器之前使用picker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
。
答案 1 :(得分: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
打开图片。 我认为这是您的问题。我已对该特定行发表评论,要求您进行检查。答案 2 :(得分:0)
将.modalPresentationStyle
设置为fullScreen