我目前正在使用AVFoundation来运行我的相机,但我希望能够检测相机何时完成对焦。有没有办法做到这一点?
非常感谢!!
答案 0 :(得分:9)
根据doc
您可以使用
adjustingFocus
属性来确定设备 目前正在关注。您可以使用key-value observing
观察该属性,以便在设备启动时停止通知并停止对焦。如果更改对焦模式设置,则可以将它们还原为 默认配置如下:
答案 1 :(得分:6)
在初始化中:
[[[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;
}
}
}
}