相机叠加视图 - 仅用于预览? [英] camera overlay view - just for preview?

查看:15
本文介绍了相机叠加视图 - 仅用于预览?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在 OS 3.1 中,您可以使用

I've noticed that in OS 3.1 you can add an overlay view to the image picker with

cameraOverlayView

但是,我也注意到通过此方法添加视图也会在整个 UIImagePicker 显示期间显示视图,而我只想在预览阶段显示它.

However, I've also noticed that adding a view via this method also displays the view for the entire time the UIImagePicker is displayed, when I only want to show it during the preview stage.

有没有办法让这仅在预览期间发生?我不希望它在打开快门动画期间出现,或者在屏幕询问您是要使用图像还是重拍时出现.

Is there a way to make this only happen during preview? I don't want it to be there during the open shutter animation, or the screen that asks whether you want to use the image or retake.

推荐答案

我已经为您找到了一种方法来实现所需的结果,尽管它有点……不那么标准.:)

I've figured out a way for you to achieve the desired result though it's a bit... not so standard. :)

这个想法是在 UIImagePickerController 使用的结构中重新排列内部视图的顺序.

The idea is to rearrange a bit the order of the inner views in the structure UIImagePickerController uses.

好的,所以我们创建一个 UIImagePickerController 对象,对其进行初始化并添加一个覆盖视图.请注意!UIView 对象(示例代码中的UIImageView)从一开始就被隐藏了.不要错过.最后,我们将图像选择器控制器呈现为模态视图控制器.这段代码应该在你的 applicationDidFinishLaunching:viewWillAppear: 或类似的适合启动方法的地方.

OK, so we create an UIImagePickerController object, initialize it and add an overlay view to it. May I have your attention please! The UIView object (UIImageView in the example code) is hidden from the very beginning. Don't miss that. Finally we present the image picker controller as modal view controller. This code should be somewhere in your applicationDidFinishLaunching:, viewWillAppear: or similar appropriate about to launch methods.

UIImagePickerController *anImagePickerController = [UIImagePickerController new];
anImagePickerController.delegate = self;
anImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

UIImageView *anImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Watermark.png"]];
anImageView.frame = CGRectMake(0, 1, anImageView.image.size.width, anImageView.image.size.height);
anImageView.hidden = YES;
anImagePickerController.cameraOverlayView = anImageView;

[viewController presentModalViewController:anImagePickerController animated:NO];
[anImagePickerController release];

[NSTimer scheduledTimerWithTimeInterval:0.1
                                 target:self
                               selector:@selector(timerFireMethod:)
                               userInfo:anImageView
                                repeats:YES];
[anImageView release];

在覆盖视图 (anImageView) 发布之前,会创建一个 NSTimer,并使用 anImageView (NSTimer 进行初始化userInfo 属性)并立即安排.这是它调用的方法:

Before the overlay view (anImageView) is released a NSTimer is created, initialized with anImageView (NSTimer userInfo property) and scheduled right away. Here's the method it calls:

- (void)timerFireMethod:(NSTimer*)theTimer {
    UIView *cameraOverlayView = (UIView *)theTimer.userInfo;
    UIView *previewView = cameraOverlayView.superview.superview;

    if (previewView != nil) {
        [cameraOverlayView removeFromSuperview];
        [previewView insertSubview:cameraOverlayView atIndex:1];

        cameraOverlayView.hidden = NO;

        [theTimer invalidate];
    }
}

整个 NSTimer 东西被添加到流程中,以确保重新排序工作将在 UIImagePickerController 完全准备好时发生.

The whole NSTimer thing is added to the flow to ensure that the reordering work around will happen exactly when the UIImagePickerController will be totally ready for that.

就是这样.它有效,它不是标准的,它是粗糙和快速的.再次随意优化并使其更正确"(哦,请这样做,我的目的是为您指明方向).

This is it. It works, it's not standard, it's rough and quick. Again feel free to optimize and make it 'righter' (oh please do, my aim was to show you the way).

这篇关于相机叠加视图 - 仅用于预览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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