码迷,mamicode.com
首页 > 移动开发 > 详细

ios开发之手电使用补充

时间:2017-03-31 13:20:56      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:har   focus   nbsp   import   bsp   iat   order   创建   exp   

今天看自己之前的scanning,发现对于照明说的不是很清楚,这里重新写一次,也做收藏

#import <AVFoundation/AVFoundation.h>   //需要引用框架

- (void)lightSwitch:isOn{

AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; //创建Video类型的驱动对象用于启动手电筒

   if (![captureDevice hasTorch]) return;  //检测是否有灯光

    if(![captureDevice hasFlash])  return; //检测是否有灯光

    [captureDevice lockForConfiguration:nil];

//  官方解释,必须要持一个设备锁  --------In order to set hardware properties on an AVCaptureDevice, such as focusMode and exposureMode, clients must first acquire a lock on the device. Clients should only hold the device lock if they require settable device properties to remain unchanged. Holding the device lock unnecessarily may degrade capture quality in other applications sharing the device.

    isOn = !isOn;

    captureDevice.torchMode = isOn? AVCaptureTorchModeOn:AVCaptureTorchModeOff;

    [captureDevice unlockForConfiguration];

}

ios开发之手电使用补充

标签:har   focus   nbsp   import   bsp   iat   order   创建   exp   

原文地址:http://www.cnblogs.com/chims-liu-touch/p/6650625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!