【问题标题】:Keep torch on while taking video iOS swift快速拍摄 iOS 视频时保持手电筒开启
【发布时间】:2017-03-22 06:28:18
【问题描述】:

我构建了一个用于自动捕捉的相机应用。只要相机打开,我就想保持闪光灯打开。我设置了以下代码:

 cameraDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
    if (cameraDevice.hasTorch) {
        do {
            try cameraDevice.lockForConfiguration()

            if cameraDevice.isTorchActive {
                cameraDevice.torchMode = AVCaptureTorchMode.on

            } else {
                // sets the torch intensity to 100%
               try  cameraDevice.setTorchModeOnWithLevel(0.8)
            }

            cameraDevice.unlockForConfiguration()
        } catch {
            print(error)
        }
    }

但是当我运行该应用程序时,它只闪烁一次然后熄灭。我该如何解决这个问题?

【问题讨论】:

标签: ios swift camera-flash


【解决方案1】:

调用此方法

在您的相机内启用/打开func 或当设备相机处于启用状态时 -

   func flashActive() {
    if let currentDevice = AVCaptureDevice.default(for: AVMediaType.video), currentDevice.hasTorch {
        do {
            try currentDevice.lockForConfiguration()
            let torchOn = !currentDevice.isTorchActive
            try currentDevice.setTorchModeOn(level:1.0)//Or whatever you want
            currentDevice.torchMode = torchOn ? .on : .off
            currentDevice.unlockForConfiguration()
        } catch {
            print("error")
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    • 2015-01-28
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多