4

对于自定义相机叠加层,我需要找出虹膜何时打开,因为我的叠加层将始终在虹膜关闭时显示(然后动画打开)。

有任何想法吗 ?

4

5 回答 5

3

您可以收听 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];
     }
}
于 2009-11-04T15:46:11.620 回答
3

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

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

在这里查看:https ://devforums.apple.com/message/561008#561008

于 2011-10-11T15:37:46.557 回答
2

我有一个 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
于 2012-10-06T14:11:13.327 回答
0

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

于 2011-04-08T15:27:15.443 回答
-1

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

总而言之,如果有人按照我习惯使用的方式使用自定义相机叠加层,就会知道虹膜何时打开,因为它在您的控制之下。

于 2009-10-17T03:18:17.990 回答