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

发布于 2024-08-22 10:00:28 字数 81 浏览 3 评论 0原文

有没有办法在使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骑趴 2024-08-29 10:00:28

我在此处提出了类似的问题,

我的解决方案是在顶部创建一个自定义视图默认 UIImagePickerControllerView 的。

我下载了示例 增强现实

然后您可以使用 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 方法中拍照后关闭视图

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

[self dismissModalViewControllerAnimated:YES];
}

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];
}
尽揽少女心 2024-08-29 10:00:28

这是快速版本:

                /// toolbar - handy if you want to be able to exit from the image picker...
            toolBar = UIToolbar(frame: CGRect(x: 0, y: 480 - 55, width: 320, height: 55))
            toolBar?.barStyle = UIBarStyle.black
            
            let items = [
                UIBarButtonItem(barButtonSystemItem: .cancel, target: self,
                                action:#selector(cancelPicture)),
                UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
                UIBarButtonItem(barButtonSystemItem: .camera, target: self,
                                action:#selector(shootPicture))
            ]
            
            toolBar?.items = items

            // create the overlay view
            let overlayView = OverlayView()
            overlayView.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480 - 44)

            // important - it needs to be transparent so the camera preview shows through!
            overlayView.view.isOpaque = false

            picker.view.addSubview(overlayView.view)
            picker.view.addSubview(toolBar!)
            

            // hide the camera controls
            picker.showsCameraControls = false
            picker.cameraOverlayView = overlayView.view
            
            toolBar?.snp.makeConstraints{(make) ->  Void in
                make.width.equalTo(180)
                make.height.equalTo(50)
                make.top.equalTo(picker.view.snp.bottom).offset(-200)
                make.centerX.equalTo(picker.view.snp.centerX)
            }

Here's the swift version:

                /// toolbar - handy if you want to be able to exit from the image picker...
            toolBar = UIToolbar(frame: CGRect(x: 0, y: 480 - 55, width: 320, height: 55))
            toolBar?.barStyle = UIBarStyle.black
            
            let items = [
                UIBarButtonItem(barButtonSystemItem: .cancel, target: self,
                                action:#selector(cancelPicture)),
                UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil),
                UIBarButtonItem(barButtonSystemItem: .camera, target: self,
                                action:#selector(shootPicture))
            ]
            
            toolBar?.items = items

            // create the overlay view
            let overlayView = OverlayView()
            overlayView.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480 - 44)

            // important - it needs to be transparent so the camera preview shows through!
            overlayView.view.isOpaque = false

            picker.view.addSubview(overlayView.view)
            picker.view.addSubview(toolBar!)
            

            // hide the camera controls
            picker.showsCameraControls = false
            picker.cameraOverlayView = overlayView.view
            
            toolBar?.snp.makeConstraints{(make) ->  Void in
                make.width.equalTo(180)
                make.height.equalTo(50)
                make.top.equalTo(picker.view.snp.bottom).offset(-200)
                make.centerX.equalTo(picker.view.snp.centerX)
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文