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

       
    (...)
    }
  • 相关阅读:
    常用Git命令清单
    上海金瑢信息有限公司面试
    上海视频面试
    bootstrp-3.0
    B站小姐姐面试分享2
    B站小姐姐分享第一次电话面试
    Array.from()方法就是将一个类数组对象或者可遍历对象转换成一个真正的数组。
    findIndex
    es5,es6
    es6数组去重
  • 原文地址:https://www.cnblogs.com/cokecoffe/p/2598955.html
Copyright © 2011-2022 走看看