10

我目前正在使用 AVFoundation 来运行我的相机,但我希望能够检测到相机何时完成对焦。有没有办法做到这一点?

非常感谢!!

4

2 回答 2

9

根据文档

您可以使用该adjustingFocus属性来确定设备当前是否正在聚焦。您可以观察key-value observing用于在设备启动和停止对焦时收到通知的属性。

如果您更改对焦模式设置,您可以将它们恢复为默认配置,如下所示:

于 2013-01-30T05:00:25.737 回答
7

在初始化中:

[[[captureManager videoInput] device] addObserver:self forKeyPath:@"adjustingFocus" options:NSKeyValueObservingOptionNew context:nil];

进而:

bool focusing = false;  
bool finishedFocus = false;
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    //[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    if( [keyPath isEqualToString:@"adjustingFocus"] ){
        BOOL adjustingFocus = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualToNumber:[NSNumber numberWithInt:1] ];

        if (adjustingFocus) {
             focusing=true;
        }
        else {
           if (focusing) {
                focusing = false;
                finishedFocus = true;
           }
        }
    }
}
于 2014-01-17T11:59:46.193 回答