iPhone:camera autofocus observer? [英] iPhone : camera autofocus observer?

查看:224
本文介绍了iPhone:camera autofocus observer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

IE,是否存在在自动对焦开始时通知的方式,

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 ?

推荐答案

我发现我的情况下找到解决方案,当自动对焦开始/结束。

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"];

    (...)
}



Documentation:

  • Key-Value Observing programming guide
  • NSKeyValueObserving protocol

这篇关于iPhone:camera autofocus observer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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