简体   繁体   English

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

[英]iPhone SDK - How to disable the picture preview in UIImagePickerController?

Is there any way to disable the image preview after taking a picture with the UIImagePickerController? 使用UIImagePickerController拍照后有没有办法禁用图像预览? I want to dismiss the ImagePicker as soon as the user pressed the shutter release button. 我想在用户按下快门释放按钮后立即关闭ImagePicker。

I asked a similar question here 在这里问了一个类似的问题

My solution was to create a customized view on top of the default UIImagePickerControllerView. 我的解决方案是在默认的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. 然后你可以使用OverlayView.m和OverlayView.h将它们添加到你的项目中:我创建了自定义选择工具栏,选择器和overlayView全局,以便我可以在项目的任何地方访问它们。

In your ViewController.h 在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): (shootPictureMethod):

-(void) shootPicture {

    [picker takePicture];

}

To exit without showing preview just dismiss the view after taking the picture in the didFinishPickingImage method 要退出而不显示预览,只需在didFinishPickingImage方法中拍摄照片后关闭视图

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

[self dismissModalViewControllerAnimated:YES];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UIImagePickerController没有加载到iPhone SDK的viewDidLoad中 - UIImagePickerController not loading in viewDidLoad for iPhone SDK 如何在iPhone应用程序中禁用/隐藏UIImagePickerController相机快门? - How to disable/Hide the UIImagePickerController Camera shutter in iPhone app? UIImagePickerController返回的图像大于iPhone 4上的预览 - UIImagePickerController Image returned is bigger than preview on iPhone 4 iPhone:UIImagePickerController随机无法拍照 - iPhone: UIImagePickerController Randomly Fails to Take Picture iPhone SDK UI元素预览 - iPhone SDK UI element preview iPhone SDK相机重叠动画,如何在预览中停止? - iphone sdk camera overlay animation, how can stop in preview? iPhone SDK - 如何使用自定义相机视图拍摄照片? - iPhone SDK - How to take a picture with custom camera view? 在iPhone中的UIImagepickercontroller委托中显示视频预览时调用什么方法 - what method that is called when showing video preview in UIImagepickercontroller delegate in iphone 如何在 UIImagePickerController 中禁用视频捕获 - How to disable video capture in UIImagePickerController 通过使用UIImagePickerController,我可以裁剪图片并将其保存在iPhone目录中吗? - by using UIImagePickerController, i can crop the picture and also save it in iphone directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM