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

即,是否存在一种在自动对焦开始,结束时成功或失败的通知方式?

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

最佳答案

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

在我的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"];

    (...)
}


说明文件:


Key-Value Observing programming guide
NSKeyValueObserving protocol

关于iphone - iPhone:相机自动对焦观察器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9100357/

10-10 18:35