Skip to content

Instantly share code, notes, and snippets.

@bsdshell
Last active August 29, 2015 14:26
Show Gist options
  • Save bsdshell/31d56609ead81258c985 to your computer and use it in GitHub Desktop.
Save bsdshell/31d56609ead81258c985 to your computer and use it in GitHub Desktop.
UIImagePickerController simple example, Override camera button, OverlayView example
@interface ViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>{
NSMutableArray* _capturedImages;
}
@property(nonatomic, retain)NSMutableArray* capturedImages;
@end
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
if (imagePickerController.sourceType == UIImagePickerControllerSourceTypeCamera){
imagePickerController.showsCameraControls = NO;
imagePickerController.cameraOverlayView = self.overlayView;
imagePickerController.delegate = self;
self.overlayView = nil;
}
self.imagePickerController = imagePickerController;
// The method have to pass (id)sender as parameter in order to work:)
- (void)takePicture:(id)sender
{
NSLog(@"takePicture()");
[self.imagePickerController takePicture];
}
#pragma mark - UIImagePickerControllerDelegate
// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
[self.capturedImages addObject:image];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:NULL];
}
@bsdshell
Copy link
Author

UIImagePickerController simple example
note: - (void)takePicture:(id)sender has to be this form in order to work,
Take a while to figure it out.
Initially use:
(void)takePicture{
}
but the camera can't take any picture

@bsdshell
Copy link
Author

Two Lines are important
imagePickerController.showsCameraControls = NO;
UIView* overlayView = [UIView alloc]init];
imagePickerController.cameraOverlayView = self.overlayView;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment