闪光灯的打开、关闭
作者:
ZJ_偶尔上路 | 来源:发表于
2017-09-18 17:08 被阅读0次- (void)openFlash:(UIButton *)sender {
sender.selected = !sender.selected;
if (sender.isSelected == YES) { //打开闪光灯
AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
if ([captureDevice hasTorch]) {
BOOL locked = [captureDevice lockForConfiguration:&error];
if (locked) {
captureDevice.torchMode = AVCaptureTorchModeOn;
[captureDevice unlockForConfiguration];
}
}
}else{//关闭闪光灯
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch]) {
[device lockForConfiguration:nil];
[device setTorchMode: AVCaptureTorchModeOff];
[device unlockForConfiguration];
}
}
}
本文标题:闪光灯的打开、关闭
本文链接:https://www.haomeiwen.com/subject/uxmbsxtx.html
网友评论