Hide/Show iPhone Camera Iris/Shutter animation

后端 未结 7 970
执笔经年
执笔经年 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:46

    Came across a similar: I wanted to have the shutter appear when I take the picture triggered by a button in a self.cameraOverlayView of a UIImagePickerController. Arrived to this page, did some extra research and came to this solution.

    Synopsis:

    @interface MyController : UIImagePickerController
    ...    
    - (id) init {
    ...
        self.cameraOverlayView = _my_overlay_;
        self.showsCameraControls = NO;
    ...
    }
    ... 
    - (void) onMyShutterButton {
        [self takePicture]; 
            // You want the shutter animation to happen now.
            // .. but it does not.
    }
    

    Solution:

    // Some constants for the iris view and selector
    NSString* kIrisViewClassName = @"PLCameraIrisAnimationView";
    SEL kIrisSelector = NSSelectorFromString(@"animateIrisOpen");
    
    @implementation MyController {
    ...
        UIView* iris_;
    }
    - (void) viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        // Find the iris view in the siblings of your overlay view
        for (UIView* view in self.cameraOverlayView.superview.subviews) {
            if ([kIrisViewClassName isEqualToString:[[view class] description]]) {
                // It will be hidden by 'self.showsCameraControls = NO'.
                view.hidden = false;   
                // Extra precautions - as this is undocumented.  
                if ([view respondsToSelector:kIrisSelector]) {
                    iris_ = view;
                }
                break;
            }
        }
    }
    - (void) animateIrisOpen {
        if (iris_) {
            [iris_ performSelector:kIrisSelector];
        }
    }
    ...
    - (void) onMyShutterButton {
        [self takePicture]; 
        [self animateIrisOpen];   // Voila - the shutter happens
    }
    

提交回复
热议问题