iPhone:相机自动对焦观察者? [英] iPhone : camera autofocus observer?

查看:18
本文介绍了iPhone:相机自动对焦观察者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在 iPhone 应用程序中接收有关自动对焦的通知?

I would like to know if it's possible to receive notification about autofocus inside an iPhone application?

即,是否有一种方法可以在自动对焦开始、结束、成功或失败时收到通知......?

I.E, does it exist a way to be notified when autofocus starts, ends, if it has succeed or failed... ?

如果是,这个通知名称是什么?

If so, what is this notification name ?

推荐答案

我找到了适合我的案例的解决方案,以找到自动对焦何时开始/结束.它只是在处理 KVO(键值观察).

I find the solution for my case to find when autofocus starts / ends. It's simply dealing with KVO (Key-Value Observing).

在我的 UIViewController 中:

In my UIViewController:

// callback
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if( [keyPath isEqualToString:@"adjustingFocus"] ){
        BOOL adjustingFocus = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualToNumber:[NSNumber numberWithInt:1] ];
        NSLog(@"Is adjusting focus? %@", adjustingFocus ? @"YES" : @"NO" );
        NSLog(@"Change dictionary: %@", change);
    }
}

// register observer
- (void)viewWillAppear:(BOOL)animated{
    AVCaptureDevice *camDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    int flags = NSKeyValueObservingOptionNew; 
    [camDevice addObserver:self forKeyPath:@"adjustingFocus" options:flags context:nil];

    (...)   
}

// unregister observer
- (void)viewWillDisappear:(BOOL)animated{
    AVCaptureDevice *camDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    [camDevice removeObserver:self forKeyPath:@"adjustingFocus"];

    (...)
}

文档:

这篇关于iPhone:相机自动对焦观察者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆