Creating A Preview Screen With A Custom Camera

前端 未结 1 1839
孤城傲影
孤城傲影 2020-12-29 16:49

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 optio

相关标签:
1条回答
  • 2020-12-29 17:37

    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.

    0 讨论(0)
提交回复
热议问题