如何快速观察火炬水平?

时间:2016-10-14 02:07:46

标签: swift avfoundation key-value-observing kvocontroller

我如何观察torchLevel?我从目标c解决方案中做了以下工作,但没有成功:

private var torchLevel = 0

let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    device.addObserver(self, forKeyPath: "torchLevel", options: .New, context: &torchLevel)

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
    if context == &torchLevel {
        let device = object as! AVCaptureDevice
        print("level \(device.torchLevel)")
    } else {
        print("Nope")
    }
}

我的另一个方向是关闭手电筒并将变量设置为0.0并在操作闪光灯时更新它。

0 个答案:

没有答案