cameraOverlayView above Shutter animation

心已入冬 提交于 2019-12-07 10:13:06

问题


I have a transparent view with a rectangle drawn onto it using 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.

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

回答1:


On the iPad this problem doesn't exist, and the overlay view is behind the shutter animation by default. But on the iPhone, the overlay appears at front.

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/




回答2:


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).

As an imperfect workaround, you could start your overlay with alpha=0 and then set alpha to 1 a second or two later. 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.




回答3:


As of 4.3.3, the shutter animation is broken because elements are displayed on top, and then snap underneath when the animation starts. I've filed this as a Radar: http://openradar.appspot.com/radar?id=1204401




回答4:


I answered a similar question here. What worked for me (in iOS 6) was setting the cameraOverlayView in navigationController:willShowViewController:animated.

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


来源:https://stackoverflow.com/questions/5439130/cameraoverlayview-above-shutter-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!