弹出到相机 UIImagePickerViewController 时禁用模糊视图

Disabled blur view when pop to camera UIImagePickerViewController

我在我的应用程序中显示相机模式下的 UIImagePickerController 模态。当用户拍摄照片时,我将使用拍摄的图像在 UIImagePickerController 上推送一个新的视图控制器。像这样 -

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
    let myViewController = MyViewController(nibName: "MyViewController", bundle: NSBundle.mainBundle(), andImageData: UIImageJPEGRepresentation(image, 1.0))
    picker.pushViewController(myViewController, animated: true)
}

myViewController 在其 UIImageView 中显示图像。

但是当我从 myViewController 弹出时,我看到模糊的图像覆盖和禁用的控件。我实际上想在弹出时查看相机预览。

我已经确认没有需要删除的camerOverlayView。我现在让它工作的方法是将 sourceType 设置为 PhotoLibrary 并返回到 Camera,从而强制重新初始化相机。但是我想知道为什么会出现这种模糊的视图以及如何完全避免它。

因为您正在使用 UIImagePickerController

根据文档;

The UIImagePickerController class manages customizable,
system-supplied user interfaces for taking pictures and movies on
supported devices, and for choosing saved images and movies for use
in your app. An image picker controller manages user interactions and delivers the results of those interactions to a delegate object.

如您所见,上面写着“系统提供的” 所以当您使用它拍照时,实际上您使用的是系统相机。打开相机应用程序,然后转到图书馆并返回。你会再次看到模糊。可能 iPhone 需要一些时间来重新激活相机,看到冻结的视图对用户体验不利。

看来问题是我在使用默认相机控件 (showsCameraControls = true) 的同时在 UIImagePickerController 上推送了一个新的视图控制器。这是不允许的。拍摄图像时,必须关闭拾取器控制器。来自文档 -

If you set this property to false and provide your own custom controls, you can take multiple pictures before dismissing the image picker interface. However, if you set this property to true, your delegate must dismiss the image picker interface after the user takes one picture or cancels the operation.

我现在使用 cameraOverlayView 并在其上添加自定义控件。我可以拍照、推送新视图并返回相机,没有任何问题。