简体   繁体   English

cameraOverlayView以上快门动画

[英]cameraOverlayView above Shutter animation

I have a transparent view with a rectangle drawn onto it using CoreGraphics. 我有一个透明的视图,使用CoreGraphics在其上绘制了一个矩形。 When the camera launches the custom overlay view is above the shutter animation. 相机启动时,自定义叠加视图位于快门动画上方。 What you see is the standard camera shutter with the custom rectangle above it. 您所看到的是标准的相机快门,其上方有自定义矩形。 How do I get it to go in the right place, underneath the shutter animation? 如何在快门动画下方将其正确放置? I've looked at other sample code but it's for OS 3.1 and doesn't seem to do anything differently. 我看过其他示例代码,但这是针对OS 3.1的,似乎没有什么不同。

Here's my code: 这是我的代码:

-(IBAction)cameraButton{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerCameraDeviceRear]){

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType =  UIImagePickerControllerSourceTypeCamera;

    //Add the OverlayView with the custom Rectangle
    CGRect overlayFrame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
    OverlayView *overlayView = [[OverlayView alloc]initWithFrame:overlayFrame];
    picker.cameraOverlayView = overlayView;
    [overlayView release];

    [self presentModalViewController:picker animated:YES];
    [picker release];
}
}

On the iPad this problem doesn't exist, and the overlay view is behind the shutter animation by default. 在iPad上,此问题不存在,并且默认情况下,叠加视图位于快门动画之后。 But on the iPhone, the overlay appears at front. 但是在iPhone上,叠加层显示在前面。

I've found a solution that worked for me. 我找到了适合我的解决方案。

You have to set your overlay view as a subview in this method: 您必须使用此方法将叠加视图设置为子视图:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (!viewController)
        return;

    UIView* controllerViewHolder = viewController.view;
    UIView* controllerCameraView = [[controllerViewHolder subviews] objectAtIndex:0];
    UIView* controllerPreview = [[controllerCameraView subviews] objectAtIndex:0];
    [controllerCameraView insertSubview:self.overlayView aboveSubview:controllerPreview];
}

Hope it helps 希望能帮助到你

Original source: http://www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/ 原始来源: http//www.alexcurylo.com/blog/2009/06/18/uiimagepickercontroller-in-3-0/

You may not do anything else other than what you're already doing; 除了已经在做的事情之外,您可能别无选择。 if iOS decides to put your overlay view over the shutter, you'll just have to live with it (unless you want to risk getting rejected from the app store). 如果iOS决定将叠加视图放在快门上,则只需要使用它即可(除非您想冒被应用商店拒绝的风险)。

As an imperfect workaround, you could start your overlay with alpha=0 and then set alpha to 1 a second or two later. 作为一种不完善的解决方法,您可以使用alpha = 0来启动叠加层,然后一两秒后将alpha设置为1。 But there is no set time period that the shutter appears for before 'opening' (I think it depends on how long it takes to initialize the camera hardware), so sometimes your interface might not appear until late and sometimes might appear too early. 但是没有在“打开”之前出现快门的设定时间(我认为这取决于初始化相机硬件所需的时间),因此有时您的界面可能要等到很晚才出现,有时可能出现得太早。

I answered a similar question here . 在这里回答了类似的问题。 What worked for me (in iOS 6) was setting the cameraOverlayView in navigationController:willShowViewController:animated. 对我有用的(在iOS 6中)是在navigationController:willShowViewController:animated中设置cameraOverlayView。

- (void) navigationController:(UINavigationController*) navigationController willShowViewController:(UIViewController*) viewController animated:(BOOL) animated {
    self.imagePickerController.cameraOverlayView = ...; // your camera overlay view
}

As of 4.3.3, the shutter animation is broken because elements are displayed on top, and then snap underneath when the animation starts. 从4.3.3版本开始,由于元素显示在顶部,因此动画被破坏,然后在动画开始时捕捉到下面。 I've filed this as a Radar: http://openradar.appspot.com/radar?id=1204401 我已将其作为雷达提交: http : //openradar.appspot.com/radar?id=1204401

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM