3

I'm creating an app where I made a custom overlay for the camera. I noticed that when I used the normal defaults for the camera, a preview comes up where you have the option to retake the photo or to use it. Is there an easy way to show that screen when working with custom overlays? Thanks!

rmaddy
  • 298,130
  • 40
  • 468
  • 517
A.J. S.
  • 218
  • 4
  • 15

1 Answers1

6

Yes..... for this you have to create one camera overlay view programmatically .

And then write this code...

   //set our custom overlay view

    imagePickerController.cameraOverlayView = overlayView;
    imagePickerController.showsCameraControls = NO;

To show a overlay view on the camera screen , use above code. For adding overlay view no need to use addSubView method.

When you will use the normal camera, then by default cancel button, use, Ratake and camera reverse button comes on your screen. And if you will make showsCameraControls "NO". then these button won't come. Then programmatically you have to add UIButton on camera overlay View and set their functionality.

Here i am adding one button on Camera overlay view.

     //add Camera Reverse button to the overlay view.

    UIButton *btnCamReverse = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [btnCamReverse setBackgroundImage:[UIImage imageNamed:@"image.png"]   
                                                 forState:UIControlStateNormal];

    //set the frame
    CGRect btnCamReverseFrame = CGRectMake(400, 250, 50, 50);
    btnCamReverse.frame = btnCamReverseFrame;

    [btnCamReverse addTarget:self
                  action:@selector(onClickButtonCamReverse:)
        forControlEvents:UIControlEventTouchUpInside];

    [overlayView addSubview:btnCamReverse];



    //IBAction (for switching between front and rear camera).

    -(IBAction)onClickButtonCamReverse:(id)sender
    {
      if(imagePickerController.cameraDevice == UIImagePickerControllerCameraDeviceFront)
        {
          imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
        }
      else 
        {
          imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        }
    }

For camera overlay example open the below link.....

https://github.com/anka/bw_examples

Camera with Custom View

It worked for me... I hope it works for you as well.

Community
  • 1
  • 1
Anand Gautam
  • 2,462
  • 3
  • 32
  • 64
  • @AJ.SIf you have any doubt related to the answer then ask...? – Anand Gautam Jun 05 '13 at 10:59
  • Thanks! I just now realized that I can make the buttons and screens myself, I appreciate the help!! – A.J. S. Jun 09 '13 at 07:36
  • When presenting a UIViewController from my overlay, I get this: Presenting view controllers on detached view controllers is discouraged. What is the best way to present a View Controller from an overlay? – Luke Irvin May 21 '14 at 05:47
  • @LukeIrvin In IOS 10 in cameroverlayview flashmode button is not working, when is turn the flag on of showing camera controls then it is working fine but with out camera control it is not working.. here is my question, any help would be appreciable http://stackoverflow.com/questions/40416737/uiimagepickercontroller-flashmode-is-not-working-on-ios-10-swift – Steve Nov 04 '16 at 06:53