iPhone SDK - 如何禁用 UIImagePickerController 中的图片预览?

标签 iphone camera uiimagepickercontroller photo preview

有没有办法在使用 UIImagePickerController 拍照后禁用图像预览?我想在用户按下快门释放按钮后立即关闭 ImagePicker。

最佳答案

我问了类似的问题here

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

我下载了示例Augmented Reality

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

在你的 ViewController.h 中

@class OverlayView;

@interface ViewController //bla bla...
{
UIImagePickerController * picker;
UIToolbar *toolBar;
OverlayView *overlayView; 
}

我创建了工具栏的控件:相机按钮和取消按钮

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

(shootPictureMethod):

-(void) shootPicture {

    [picker takePicture];

}

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

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo 
{
//do whatever

[self dismissModalViewControllerAnimated:YES];
}

关于iPhone SDK - 如何禁用 UIImagePickerController 中的图片预览?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2300616/

相关文章:

ios - 无法在 UIImagePickerController didFinishPickingMediaWithInfo : 中获取开始和结束编辑时间

iphone - 在 iPhone 应用程序中加载文本数据

iphone - 在 ARC 上使用@property

android - 如何检测是否有前置摄像头,如果有如何够到和使用前置摄像头?

iphone - UIImagePickerController 在快速滚动时崩溃,比照片应用程序慢

iphone - 通过SDK覆盖iPhone快门声音

iphone - 使用 NSNumberFormatter 在货币符号和值之间填充空格

iphone - iOS UIWebview 加载本地设备 HTML 文件路径

android - 使用相机拍摄照片并将其保存在特定文件夹中

javascript - 三个jslensflare渲染在外面