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?
- I have created a
UIImagePickerController
that works with standard controls - For the overlay I have created a new
UIViewController
on my storyboard and linked it to a new class calledObViewControllerCameraOverlay
In the
startCameraControllerFromViewController
method I use the following to hide the standard controlscameraUI.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 aUIView *
type. If you want to pass anUIViewController
as an overlay view you have to pass only it'sview
property.For example:
You should change the code of course according to your project and configuration.