dan*_*dan 17 iphone camera photo preview uiimagepickercontroller
使用UIImagePickerController拍照后有没有办法禁用图像预览?我想在用户按下快门释放按钮后立即关闭ImagePicker.
era*_*uki 16
我在这里问了一个类似的问题
我的解决方案是在默认的UIImagePickerControllerView之上创建一个自定义视图.
我下载了增强现实的例子
然后你可以使用OverlayView.m和OverlayView.h将它们添加到你的项目中:我创建了自定义选择器工具栏,选择器和overlayView全局,以便我可以在项目的任何地方访问它们.
在ViewController.h中
@class OverlayView;
@interface ViewController //bla bla...
{
UIImagePickerController * picker;
UIToolbar *toolBar;
OverlayView *overlayView;
}
Run Code Online (Sandbox Code Playgroud)
我创建了工具栏的控件,一个相机按钮和取消按钮
// 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;
Run Code Online (Sandbox Code Playgroud)
取消方法
- (IBAction)cancel {
// Don't pass current value to the edited object, just pop.
[self.navigationController popViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
(shootPictureMethod):
-(void) shootPicture {
[picker takePicture];
}
Run Code Online (Sandbox Code Playgroud)
要退出而不显示预览,只需在didFinishPickingImage方法中拍摄照片后关闭视图
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo
{
//do whatever
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18290 次 |
最近记录: |