Question

When I try and apply a cameraOverlayView to UIImagePickerController, it doesn't show up. I have read through some documentation on how to apply this, and my code all looks correct. If someone could explain why my overlay isn't starting, I would really appriciate it.

//Start the camera up

UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];

//Hide default UI elements

imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
imageViewPickerController.navigationBarHidden = YES;
imageViewPickerController.toolbarHidden = YES;

//Start the button overlay

UIView *btnView = [[UIView alloc] initWithFrame:imageViewPickerController.view.bounds];
btnView.backgroundColor = [UIColor whiteColor];
btnView.alpha = 0.3;
btnView.clipsToBounds = YES;

//Add a button to the overlay

UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024)];
snapButton.backgroundColor = [UIColor blackColor];
[btnView addSubview:snapButton];

//Overlay button view

imageViewPickerController.cameraOverlayView = btnView;

//Fix for iPhone 5 and make fullscreen

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
imageViewPickerController.cameraViewTransform = transform;

//Let's present it all

[self presentViewController:imageViewPickerController
                   animated:NO
                 completion:NULL];

SOLUTION:

I found the solution: it was both merging in Visput's suggestion, and fguchelaar's. I then removed the btnView.alpha = 0.3 and replaced it with btnView.opaque = NO; and that did the trick. Messed around with colors and now my overlay is working perfectly.

Was it helpful?

Solution

Frame of your overlay view has zero size:

UIView *btnView = [[UIView alloc] initWithFrame:CGRectZero];

Change it like this and you will see it:

UIView *btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 1024];

Update:
Also enable clipsToBounds flag: btnView.clipsToBounds = YES;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top