Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 933
MA2 Avatar asked Mar 23 '23 10:03

MA2


1 Answers

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
})
like image 71
T. Hyldgaard Avatar answered May 07 '23 09:05

T. Hyldgaard