我如何观察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并在操作闪光灯时更新它。