Search code examples
iosswiftuiimagepickercontrollerios-camera

Disabled blur view when pop to camera UIImagePickerViewController


I am showing a UIImagePickerController modal in camera mode in my app. When the user takes a photo I am pushing a new view controller on the UIImagePickerController with the image that was taken. Like this -

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)
}

The myViewController shows the image in its UIImageView.

But when I pop back from myViewController, I see a blurred image overlay and disabled controls. I actually want to see the camera preview when I pop back.

I have confirmed that there is no camerOverlayView that needs to be removed. The way I am getting this to work now is to set the sourceType to PhotoLibrary and back to Camera thus forcing a reinitializing of the camera. But I would like to know why this blurred view is appearing and how to avoid it altogether.

enter image description here


Solution

  • So it looks like the problem was that I was pushing a new view controller on UIImagePickerController while using the default camera controls (showsCameraControls = true). This is not allowed. The picker controller necessarily has to be dismissed when an image is taken. From the documentation -

    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.

    I and now using a cameraOverlayView and adding custom controls on it. I can take picture, push a new view and pop back to camera without any problems.