我目前正在使用 AVFoundation 来运行我的相机,但我希望能够检测到相机何时完成对焦。有没有办法做到这一点?
非常感谢!!
根据文档
您可以使用该
adjustingFocus
属性来确定设备当前是否正在聚焦。您可以观察key-value observing
用于在设备启动和停止对焦时收到通知的属性。如果您更改对焦模式设置,您可以将它们恢复为默认配置,如下所示:
在初始化中:
[[[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;
}
}
}
}