Creating A Preview Screen With A Custom Camera

不打扰是莪最后的温柔 提交于 2019-12-18 12:03:05

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/16933811/creating-a-preview-screen-with-a-custom-camera

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!