gpt4 book ai didi

iPhone : camera autofocus observer?

转载 作者:行者123 更新时间:2023-12-03 18:21:12 25 4
gpt4 key购买 nike

我想知道是否可以在 iPhone 应用程序内接收有关自动对焦的通知?

即,是否存在一种在自动对焦开始、结束、成功或失败时收到通知的方法...?

如果是,该通知名称是什么?

最佳答案

我找到了适合我的案例的解决方案,以查找自动对焦何时开始/结束。它只是处理 KVO(键值观察)。

在我的 UIViewController 中:

// callback
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if( [keyPath isEqualToString:@"adjustingFocus"] ){
BOOL adjustingFocus = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualToNumber:[NSNumber numberWithInt:1] ];
NSLog(@"Is adjusting focus? %@", adjustingFocus ? @"YES" : @"NO" );
NSLog(@"Change dictionary: %@", change);
}
}

// register observer
- (void)viewWillAppear:(BOOL)animated{
AVCaptureDevice *camDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
int flags = NSKeyValueObservingOptionNew;
[camDevice addObserver:self forKeyPath:@"adjustingFocus" options:flags context:nil];

(...)
}

// unregister observer
- (void)viewWillDisappear:(BOOL)animated{
AVCaptureDevice *camDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[camDevice removeObserver:self forKeyPath:@"adjustingFocus"];

(...)
}

文档:

关于iPhone : camera autofocus observer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9100357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com