Hide/Show iPhone Camera Iris/Shutter animation
Solution 1
Using this answer as a starting point, I've finally solved this problem:
NOTE: This is obviously not 3.3.1-compliant.
Listen for the
UINavigationControllerDidShowViewControllerNotification
on yourUIImagePickerController
, and thePLCameraViewIrisAnimationDidEndNotification
globally.Traverse the view hierarchy (starting at the main
UIWindow
) looking for thePLCameraView
. Save the index of the view against the mainUIWindow
, as you'll need it later.Remove the
PLCameraView
from itssuperView
. If desired, insert your own view at global index 0.When the iris animation is finished, remove your view and re-add the
PLCameraView
at its original index.
Solution 2
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
}
Ankur
Updated on July 20, 2022Comments
-
Ankur almost 2 years
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. Is there a way to remove the initial shutter(also known as Iris) animation as the camera starts. Thank You
[EDIT]
For those who wants to know the way to change the camera iris animation.
The below function is called before the camera iris animation starts.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // Here is were I make the camera preview fit the entire screen. // This might violate the "don't change the view hierarchy"-rule. // So I am not sure if it is valid for App Store commitment. // However, the NSLogs are used to // figure out which subview is the actual Camera Preview which turns out // to be the PLPreviewView. (uncomment to se the printouts). // Change it's size to fit the entire screen (and scale it accordingly // to avoid distorted image NSLog(@"WillShowViewController called..."); NSLog(@"VC:view:subviews\n %@\n\n", [[viewController view] subviews]); NSLog(@"VC:view:PLCameraView:subviews\n %@\n\n", [[[[viewController view] subviews] objectAtIndex: 0] subviews]); NSLog(@"VC:view:PLCameraView:PLPreviewView:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 0] subviews]); NSLog(@"VC:view:PLCameraView:PLCropOverLay:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 1] subviews]); NSLog(@"VC:view:PLCameraView:UIImageView:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 2] subviews]); }
In the above function you can go through each layer by using the normal NSMuatableArray syntax like objectAtIndex
hope this might help you.
Regards,
Ankur
-
Ankur over 12 yearsThank you Harsh for formatting the code. I didn't know the shortcut for that.
-
Janak Nirmal over 12 yearsCan you please post your code in your question itself as I am facing same issue and need to hide that animation of shutter.
-
AmineG over 12 yearsyes, it does not work on iOS5, I tried replacing that with AVCaptureSessionDidStartRunningNotification and AVCaptureSessionDidStopRunningNotification, but it work on iOS5 and not with the same behaviour on iOS 4