iPhone SDK - 如何在 UIImagePickerController 中禁用图片预览? [英] iPhone SDK - How to disable the picture preview in UIImagePickerController?

查看:17
本文介绍了iPhone SDK - 如何在 UIImagePickerController 中禁用图片预览?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在使用 UIImagePickerController 拍照后禁用图像预览?我想在用户按下快门按钮后立即关闭 ImagePicker.

Is there any way to disable the image preview after taking a picture with the UIImagePickerController? I want to dismiss the ImagePicker as soon as the user pressed the shutter release button.

推荐答案

我问了一个类似的问题 这里

I asked a similar question here

我的解决方案是在默认的 UIImagePickerControllerView 之上创建一个自定义视图.

My solution was to create a customized view on top of the default UIImagePickerControllerView.

我下载了示例增强现实

然后您可以通过将 OverlayView.m 和 OverlayView.h 添加到您的项目中来使用它们:我将自定义选择器工具栏、选择器和 overlayView 设为全局,以便我可以在项目中的任何位置访问它们.

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.

在你的 ViewController.h 中

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;

取消方法

- (IBAction)cancel {
    // Don't pass current value to the edited object, just pop.
    [self.navigationController popViewControllerAnimated:YES];
}

(拍摄图片方法):

-(void) shootPicture {

    [picker takePicture];

}

要退出而不显示预览,只需在 didFinishPickingImage 方法中拍照后关闭视图

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];
}

这篇关于iPhone SDK - 如何在 UIImagePickerController 中禁用图片预览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆