Hide/Show iPhone Camera Iris/Shutter animation

后端 未结 7 985
执笔经年
执笔经年 2020-12-05 06:00

I am not able to Hide the iphone Camera shutter opening animation for my app. I am using UIImagePickerController to access iphone camera and using my own overlay controllers

7条回答
  •  囚心锁ツ
    2020-12-05 06:33

    joshwa's answer completely hides the entire camera view for the duration of the iris animation. For my purposes, I needed the camera view visible, just without the iris animation. I was able to accomplish this with a little tweaking of his method. As others have noted, this may or may not be allowed on the app store since we're messing with the view hierarchy as well as listening for undocumented notifications.

    3 ivars are needed:

    UIImagePickerController *imagePickerController;
    UIView *plCameraIrisAnimationView;  // view that animates the opening/closing of the iris
    UIImageView *cameraIrisImageView;  // static image of the closed iris
    

    Hide the closed iris image and remove the animation view. I tried simply hiding the animation view as well, but the animation was still visible:

    - (void)receivedNavigationControllerDidShowViewControllerNotification:(NSNotification *)notification {
        UIView *view = imagePickerController.view;
        [plCameraIrisAnimationView release];
        plCameraIrisAnimationView = nil;
        cameraIrisImageView = nil;
        while (view.subviews.count && (view = [view.subviews objectAtIndex:0])) {
            if ([[[view class] description] isEqualToString:@"PLCameraView"]) {
                for (UIView *subview in view.subviews) {
                    if ([subview isKindOfClass:[UIImageView class]]) {
                        cameraIrisImageView = (UIImageView *)subview;
                    }
                    else if ([[[subview class] description] isEqualToString:@"PLCropOverlay"]) {
                        for (UIView *subsubview in subview.subviews) {
                            if ([[[subsubview class] description] isEqualToString:@"PLCameraIrisAnimationView"]) {
                                plCameraIrisAnimationView = [subsubview retain];
                            }
                        }
                    }
                }
            }
        }
        cameraIrisImageView.hidden = YES;
        [plCameraIrisAnimationView removeFromSuperview];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UINavigationControllerDidShowViewControllerNotification" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedPLCameraViewIrisAnimationDidEndNotification:) name:@"PLCameraViewIrisAnimationDidEndNotification" object:nil];
    }
    

    When the animation is over, unhide the iris image and re-add the animation view:

    - (void)receivedPLCameraViewIrisAnimationDidEndNotification:(NSNotification *)notification {
        cameraIrisImageView.hidden = NO;
    
        UIView *view = imagePickerController.view;
        while (view.subviews.count && (view = [view.subviews objectAtIndex:0])) {
            if ([[[view class] description] isEqualToString:@"PLCameraView"]) {
                for (UIView *subview in view.subviews) {
                    if ([[[subview class] description] isEqualToString:@"PLCropOverlay"]) {
                        [subview insertSubview:plCameraIrisAnimationView atIndex:1];
                        [plCameraIrisAnimationView release];
                        plCameraIrisAnimationView = nil;
                        break;
                    }
                }
            }
        }
    
        [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PLCameraViewIrisAnimationDidEndNotification" object:nil];
    }
    

提交回复
热议问题