繁体   English   中英

隐藏/显示iPhone相机光圈/快门动画

[英]Hide/Show iPhone Camera Iris/Shutter animation

我无法为我的应用隐藏“ iphone相机”快门打开动画。 我正在使用UIImagePickerController来访问iphone相机并使用自己的叠加层控制器。 有没有一种方法可以在相机启动时删除初始快门(也称为虹膜)动画。 谢谢

[编辑]

对于那些想知道更改相机光圈动画的方式的人。

在照相机光圈动画开始之前,将调用以下功能。

- (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]);

}

在上面的函数中,您可以使用正常的NSMuatableArray语法(例如objectAtIndex)遍历每一层

希望对您有帮助。

问候,

安库尔

这个答案为起点,我终于解决了这个问题:

注意:这显然不兼容3.3.1。

  1. 在您的UIImagePickerController上侦听UINavigationControllerDidShowViewControllerNotification PLCameraViewIrisAnimationDidEndNotification ,并在全局上侦听PLCameraViewIrisAnimationDidEndNotification

  2. 遍历视图层次结构(从主UIWindow )以查找PLCameraView 将视图的索引保存在主UIWindow ,以备后用。

  3. 取出PLCameraViewsuperView 如果需要,在全局索引0处插入您自己的视图。

  4. 虹膜动画完成后,请移开视图,然后以其原始索引重新添加PLCameraView

遇到了类似的情况:我想让UIImagePickerController的self.cameraOverlayView中的按钮触发拍照时出现快门。 到达此页面,做了一些额外的研究并得出了这个解决方案。

概要:

@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.
}

解:

// 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
}

为了详细说明Catalin的答案(顺便说一句),我发现如果您稍微更改方法“ animateIrisOpen”,则表示效果会好一些……但值得注意。

- (void) animateIrisOpen {
    if (iris_) {
        iris_.hidden = NO;
        [iris_ performSelector:kIrisSelector];
    }
}

我已经弄乱了一点,但是将视图生命周期方法的各种组合发送到图像选择器。 (viewWillAppear,viewDidAppear等),但是我不记得哪个最终可以工作。

很抱歉回复这么晚。 我找到了解决好我使用cameraView的视图层次结构的解决方案,并在所有内容的顶部添加了自己的图层。 动画在那里发生,一旦快门打开,最顶层将被移除。 如果有人需要进一步的帮助,请告诉我,我将提供确切的步骤和语法。

-安库尔

在照相机光圈动画开始之前,将调用以下功能。

- (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]);

}

在上面的函数中,您可以使用正常的NSMuatableArray语法(例如objectAtIndex)遍历每一层

希望对您有帮助。

问候,

安库尔

在虹膜动画的持续时间内,joshwa的答案完全隐藏了整个摄影机视图。 出于我的目的,我需要可见的相机视图,而没有虹膜动画。 稍微调整一下他的方法就可以完成此任务。 正如其他人指出的那样,这可能会或可能不会在应用程序商店中允许,因为我们搞砸了视图层次结构以及侦听未记录的通知。

需要3个ivars:

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

隐藏关闭的虹膜图像并删除动画视图。 我也尝试仅隐藏动画视图,但是动画仍然可见:

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

动画结束后,取消隐藏虹膜图像并重新添加动画视图:

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

暂无
暂无

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

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