Search code examples
iosipaduiimagepickercontrollercamera-overlay

Custom Camera Overlay Not Working on iPad


I am trying to get a custom overlay working. I have a PNG image in my project. The edges have a border, while the center is transparent. In my code, I have:

 self.imagePickerController = [[UIImagePickerController alloc] init];
    [self.imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
    [self.imagePickerController setDelegate:self];
    [self.imagePickerController setCameraDevice:UIImagePickerControllerCameraDeviceRear];
    [self.imagePickerController setShowsCameraControls:NO];

    UIView *myOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
    UIImage *overlayImg = [UIImage imageNamed:@"overlay.png"];
    UIImageView *overlayBg = [[UIImageView alloc] initWithImage:overlayImg];
    [myOverlay addSubview:overlayBg];
    [self.navigationController presentViewController:self.imagePickerController animated:YES completion:nil];

When I push the button to present the controller, I get this:

enter image description here

What am I doing incorrectly that is keeping the camera from taking up the entire screen, and also not adding the overlay.png image? This is what the overlay looks like, just remember the white part is actually transparent:

enter image description here

UPDATE

I have updated code:

self.imagePickerController = [[UIImagePickerController alloc] init];
    [self.imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
    [self.imagePickerController setDelegate:self];
    [self.imagePickerController setCameraDevice:UIImagePickerControllerCameraDeviceRear];
    [self.imagePickerController setShowsCameraControls:NO];

    UIView *myOverlay = [[UIView alloc] initWithFrame:self.view.bounds];
    UIImage *overlayImg = [UIImage imageNamed:@"overlay.png"];
    UIImageView *overlayBg = [[UIImageView alloc] initWithImage:overlayImg];
    [myOverlay addSubview:overlayBg];
    [self.imagePickerController.view addSubview:myOverlay];

    [self.navigationController presentViewController:self.imagePickerController animated:YES completion:nil];

It now looks like this, getting better, but camera still only taking up a small portion of screen, and the frame not quite sized right.

enter image description here


Solution

  • You need to make connection between myOverlay and imagePickerController, so try to add myOverlay as subview of imagePickerController.view.