zoukankan      html  css  js  c++  java
  • IOS开发,摄像头对焦状态监控

    camera autofocus observer?

     I find the solution for my case to find when autofocus starts / ends. It's simply dealing with KVO (Key-Value Observing).

    In my UIViewController:

    已验证。原地址:http://stackoverflow.com/questions/9100357/iphone-camera-autofocus-observer

    // 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"];
    
        (...)
    }
  • 相关阅读:
    UGO小组冲刺第一天
    day04_07-三个函数的区别
    day06_08 字符串
    day06_07 字典操作02
    day06_06 字典操作01
    day06_05 字典
    day06_04 购物车讲解02
    day06_03 购物车讲解01
    day06_02 元组
    day06_01 上节回顾
  • 原文地址:https://www.cnblogs.com/nuanshou/p/4577053.html
Copyright © 2011-2022 走看看