I asked a similar question here
My solution was to create a customized view on top of the default UIImagePickerControllerView.
I downloaded the example Augmented Reality
Then you can use the OverlayView.m and OverlayView.h by adding them to your project:
I made the custom picker toolbar, picker and overlayView global so that I can access them anywhere in the project.
In your ViewController.h
@class OverlayView;
@interface ViewController //bla bla...
{
UIImagePickerController * picker;
UIToolbar *toolBar;
OverlayView *overlayView;
}
I created the controls of the toolbar a camera button and the cancel button
// toolbar - handy if you want to be able to exit from the image picker...
toolBar=[[[UIToolbar alloc] initWithFrame:CGRectMake(0, 480-55, 320, 55)] autorelease];
toolBar.barStyle = UIBarStyleBlackOpaque;
NSArray *items=[NSArray arrayWithObjects:
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelPicture)] autorelease],
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(shootPicture)] autorelease],
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease],
nil];
[toolBar setItems:items];
// create the overlay view
overlayView=[[[OverlayView alloc] initWithFrame:CGRectMake(0, 0, 320, 480-44)] autorelease];
// important - it needs to be transparent so the camera preview shows through!
overlayView.opaque=NO;
overlayView.backgroundColor=[UIColor clearColor];
// parent view for our overlay
UIView *parentView=[[[UIView alloc] initWithFrame:CGRectMake(0,0,320, 480)] autorelease];
[parentView addSubview:overlayView];
[parentView addSubview:toolBar];
// configure the image picker with our overlay view
picker=[[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// hide the camera controls
picker.showsCameraControls=NO;
picker.wantsFullScreenLayout = YES;
The cancel method
- (IBAction)cancel {
// Don't pass current value to the edited object, just pop.
[self.navigationController popViewControllerAnimated:YES];
}
The (shootPictureMethod):
-(void) shootPicture {
[picker takePicture];
}
To exit without showing preview just dismiss the view after taking the picture in the didFinishPickingImage method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
//do whatever
[self dismissModalViewControllerAnimated:YES];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…