I am working on an iPhone app that makes use of the camera overlay view of the UIImagePickerController. However, the problem I am running into is that my overlay is still on the screen when the picture is taken and the preview screen pops up. This looks very weird. So, I need to do one of two things, both of which are proving more difficult than I would have hoped:
I know that I can accomplish #2 by setting showsCameraControls = NO - however, I am not currently creating my own camera controls, I still want to use the default controls. It seems like a sledgehammer approach to say that I need to recreate a perfectly fine UI with a custom built interface just to get around the preview screen.
On a side rant, I find it annoying that the built in camera doesn't use a preview screen, but Apple apparently forces apps to go to great lengths to avoid using it. Seems weird.
make sure that you set the delegate as imagePicker.delegate=self;
and called the delegate methode
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
where you remove imagePicker.view
from superview (depends on the way you called it )
I hope that helps
I turn off camera controls. In doing so it turns off the preview screen. so from there you can make my own preview screen (or just don't have a preview screen at all and I just use the photo after calling takePicture(). When you call the takePicture() function, you will get your desired callback right away with is
let vc = UIImagePickerController()
vc.sourceType = .camera
vc.showsCameraControls = false
let mask = MyMaskXibClassMask(vc, self)
vc.cameraOverlayView = mask.view
vc.cameraOverlayView?.frame = self.view.bounds
self.present(vc, animated: true, completion:
{
if let camvc = vc.visibleViewController
{
camvc.addChild(mask)
}
})
Where MyMaskXibClassMask would have your button to take a photo and whatever else you need. Then also in our MyMaskXibClassMask under
@IBAction func take_picture()
{
camera.delegate = self
camera.takePicture()
}
and when you call 'takePicture()', your delegate will get called (so you can skip the preview entirely)
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With