使用自定义相机创建预览屏幕 [英] Creating A Preview Screen With A Custom Camera

查看:184
本文介绍了使用自定义相机创建预览屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中我为相机制作了自定义叠加层。我注意到,当我使用相机的正常默认值时,预览出现在那里您可以选择重新拍摄或使用它。在使用自定义叠加层时,是否有一种简单的方法来显示该屏幕?谢谢!

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!

推荐答案

是的,你必须以编程方式创建一个摄像机覆盖视图。

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.

当您使用普通相机时,默认取消按钮,使用Ratake和相机反转按钮屏幕。
如果你将使showsCameraControlsNO。那么这些按钮就不会来了。然后以编程方式你必须在相机重叠视图上添加UIButton视图并设置它们的功能。

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

IOS:具有自定义视图的摄像头

它为我工作...我希望它也适合你。

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

这篇关于使用自定义相机创建预览屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆