10

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:

  1. Remove the overlay when the preview screen is active
  2. Don't show the preview screen

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.

Dustin Wilhelmi
  • 1,769
  • 2
  • 13
  • 27
  • did you find a solution? I have the same problem: http://stackoverflow.com/q/23795453/1933185. Workarounds I found but not so nice (last post): http://iphonedevsdk.com/forum/iphone-sdk-development/21950-remove-camera-overlay-image.html. Another option as `UIImagePickerController`inherits from the `UINavigationController` there could be possibilities for a hook... – jerik May 26 '14 at 21:16
  • I ended up using the sledgehammer and making a custom camera interface - hope you have better luck than me! :) – Dustin Wilhelmi May 27 '14 at 19:27
  • the sledgehammer is my fallback :) Something tells me that the UINavigationController does have potential - I will try. – jerik May 27 '14 at 19:39

3 Answers3

1

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

M.Othman
  • 5,132
  • 3
  • 35
  • 39
  • 1
    I am using that delegate call already - but it does not get called until after the preview has been shown and the "Use" button has been clicked. – Dustin Wilhelmi Jun 25 '12 at 02:01
1

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])
aman
  • 499
  • 8
  • 18
0

You have to use NSNotificationCenter along with @"_UIImagePickerControllerUserDidCaptureItem" and @"_UIImagePickerControllerUserDidRejectItem".

When entering the preview view you can remove the overlay :) A working code example can be found here: https://stackoverflow.com/a/23899448/1933185

Community
  • 1
  • 1
jerik
  • 5,714
  • 8
  • 41
  • 80