美文网首页
闪光灯的打开、关闭

闪光灯的打开、关闭

作者: 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