Reputation: 643
I currently am using AVFoundation to run my camera, but I want to be able to detect when the camera finishes focusing. Is there any way to do this?
Thanks so much!!
Upvotes: 11
Views: 2601
Reputation: 1942
In the initialisation:
[[[captureManager videoInput] device] addObserver:self forKeyPath:@"adjustingFocus" options:NSKeyValueObservingOptionNew context:nil];
and then:
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;
}
}
}
}
Upvotes: 8
Reputation: 21805
According to doc
You can use the
adjustingFocus
property to determine whether a device is currently focusing. You can observe the property usingkey-value observing
to be notified when a device starts and stops focusing.If you change the focus mode settings, you can return them to the default configuration as follows:
Upvotes: 9