繁体   English   中英

检测相机的光圈在iPhone上打开的时间

[英]Detecting when camera's iris is open on iPhone

对于一个cutom相机覆盖,我需要找到,当虹膜打开时,因为我的覆盖层将在虹膜关闭时全部显示(然后动画打开)。

有任何想法吗 ?

您可以侦听PLCameraViewIrisAnimationDidEndNotification通知。 由于这没有正式记录,您可能违反了Apple TOS,但我认为只要您编写代码,以防止此通知的名称或合同可能发生变化(因此将来您可能没有得到这个事件)你可能会好的。 换句话说,使用计时器或其他技术来确保在虹膜打开时你想要做的事情肯定会最终发生,即使你从未收到通知......

没有防御性编程的琐碎例子。 (当然,您也可以仅针对此特定通知注册兴趣,请参阅通知中心的文档。)

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(notificationCallback:)
                                             name:nil
                                           object:nil
 ];

- (void) notificationCallback:(NSNotification *) notification {
     if ([[notification name] isEqualToString:@"PLCameraViewIrisAnimationDidEndNotification"]) {
         NSLog(@"Iris open");
         // we don't need to listen any more
         [[NSNotificationCenter defaultCenter] removeObserver:self];
     }
}

似乎PLCameraViewIrisAnimationDidEndNotification不再在iOS5中得到通知。

当虹膜完成打开时,我无法弄清楚什么是合适的解决方案,必须有另一种选择,而不是使用3秒计时器。

点击此处: https//devforums.apple.com/message/561008#561008

我有一个ViewController(ALImagePickerController),它保存,初始化并呈现UIImagePickerController作为子视图控制器(我有另一个子视图控制器用于呈现此处未显示的拍摄图像)并且当我出现时(作为模态)ALImagePickerController想要使用相机。 因此,在ViewContoller的viewDidAppear中,我添加了一个动画,以便在快门动画消失时优雅地引入相机叠加。

@interface ALImagePickerController ()

@property (nonatomic) UIImagePickerController           *cameraController;
@property (nonatomic) CameraOverlayView                 *overlayView;
....

@end

@implementation ALImagePickerController

....


- (void)viewDidLoad {
    [super viewDidLoad];

    [UIApplication sharedApplication].statusBarHidden = YES;

    self.cameraController = [UIImagePickerController new];
    self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.cameraController.delegate = self;
    self.cameraController.allowsEditing = NO;
    self.cameraController.showsCameraControls = NO;
    ....

    self.overlayView = [CameraOverlayView new];
    ....
    self.overlayView.alpha = 0;
    self.cameraController.cameraOverlayView = self.overlayView;

    .... 

     // add as child view controller
    [self addChildViewController:self.cameraController];
    [self.view addSubview:self.cameraController.view];
    [self.cameraController didMoveToParentViewController:self];
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarHidden = NO;
}


- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // smoothly bring in the overlay as the native camera shutter animation opens.
    [UIView animateWithDuration:0.2 delay:0.3 options:UIViewAnimationCurveEaseOut animations:^{
        self.overlayView.alpha = 1.f;
    } completion:nil];
}

....

@end

我解决这个问题的方法是初始化所有隐藏属性设置为YES的元素,然后在调用相机后调用3秒延迟选择器,我将所有元素设置为hidden = NO。 它不是一个理想的解决方案,但似乎有效,虹膜打开后的任何滞后都可以忽略不计。

您应该已经知道相机何时准备拍照。 至少我使用自定义相机覆盖的方式,我使用像self.sourceType = UIImagePickerControllerSourceTypeCamera;类的东西初始化视图self.sourceType = UIImagePickerControllerSourceTypeCamera; 和其他常用的设置,相机准备就绪(或“虹膜打开”)。

总之,如果我习惯使用自定义相机覆盖,我会知道虹膜何时打开,因为它在您的控制之下。

暂无
暂无

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

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