MA2
MA2

Reputation: 43

Remove UIImagePickerController cameraOverlayView in Preview

I have a UIImagePickerController and a cameraOverlayView, however when the user takes a picture, the cameraOverlay view persists in the 'Preview/Use photo/retake photo view'.

Is there a way to define a cameraOverlayView for just the first camera view?

Upvotes: 4

Views: 1098

Answers (2)

T. Hyldgaard
T. Hyldgaard

Reputation: 327

Just posting here for future references, if anyone needs it.

I've been having the same issue, and after a day of research, with a lot of trail and error, I found a way that removes the cameraOverlayView from the image preview.

When you take a photo the "_UIImagePickerControllerUserDidCaptureItem" triggers. Luckily we can utilize this by creating an observer with a closure. Inside the closure we can set the cameraOverlayView to nil, and thereby removing your custom view before entering preview.

This works in Xcode Version 8.1 (8B62), with Swift 3.

I have added the code snippet for you to utilize if needed.

NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "_UIImagePickerControllerUserDidCaptureItem"), object:nil, queue:nil, using: { note in
        self.imagePicker.cameraOverlayView = nil
})

Upvotes: 7

Jeremy Brooks
Jeremy Brooks

Reputation: 589

The preview is handled for you by the UIImagePickerController, and the overlay is always visible until the controller is dismissed.

I don't know of any way to change this behavior.

Upvotes: 0

Related Questions