I am really struggling to get my head around how to do this. I have a UIImagePickerController which works fine but I want to create my own CameraOverlayView so that I can customise the buttons. I can't seem to figure out how to create the overlay in the first place. I have tried so many tutorials and have arrived at the following but it is way off. Can anyone point me to an simple to follow instructions?
UIImagePickerController that works with standard controlsUIViewController on my storyboard and linked it to a new class called ObViewControllerCameraOverlayIn the startCameraControllerFromViewController method I use the following to hide the standard controls
cameraUI.showsCameraControls=NO;
and then this to show the cameraOverlay (which does not compile)
obViewControllerCameraOverlay *overlay = [[obViewControllerCameraOverlay alloc]; cameraUI.cameraOverlayView = overlay;
I know I am doing this wrong but I am stumped as to how to this to work. I have looked at Apple's PhotoPicker too but I just don't get it.
UPDATE:
Where I am now - can anyone tell me if this is the correct process (I realise frame size needs to be sorted and custom buttons need to be added somehow):
.m file where the 'Take Photo' UIButton is located.
@property (nonatomic, strong) UIView *overlay;
- (IBAction)takePhoto:(id)sender
{
[self startCameraControllerFromViewController: self usingDelegate: self];
}
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate
{
if (([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil)) return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerCameraCaptureModePhoto];
cameraUI.showsCameraControls=NO;
overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
cameraUI.cameraOverlayView = overlay;
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentViewController:cameraUI animated:YES completion:nil];
return YES;
}
Your overlay is only allocated - not initialized. It should be initialized and it should have it's frame properly set.
Also: overlayView should be of a UIView * type. If you want to pass an UIViewController as an overlay view you have to pass only it's view property.
For example:
obViewControllerCameraOverlay *overlay = [storyboard instantiateViewControllerWithIdentifier: @"obViewControllerCameraOverlay"];
cameraUI.cameraOverlayView = overlay.view;
You should change the code of course according to your project and configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With