zoukankan      html  css  js  c++  java
  • IOS 监听相机对焦事件

     

    来自官方文档:

    You can use the adjustingFocus property to determine whether a device is currently focusing. You can observe the property using key-value observing to be notified when a device starts and stops focusing.

     

    来自StackoverFlow:

    // 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"];

       
    (...)
    }
  • 相关阅读:
    难道真的是RedBook错了?
    用一个土办法证明RedBook的错误
    Md5 Loader Demo
    simple shadow mapping
    又遇到让人疑惑的问题
    [洛谷P1037][题解]产生数
    [洛谷P1279][题解]字串距离
    [洛谷P1122][题解]最大子树和
    [洛谷P1144][题解]最短路计数
    Vue 之 Data
  • 原文地址:https://www.cnblogs.com/cokecoffe/p/2598955.html
Copyright © 2011-2022 走看看