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!!
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:
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;
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With