KVO白平衡总是增加零

时间:2016-11-01 21:19:13

标签: swift3 key-value-observing avcapturedevice

我观察了一些AVCaptureDevice属性的变化,其中一个是白平衡增益。我的代码是:

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    if let newValue = change?[.newKey] as? NSValue {
        if context == &DeviceWhiteBalanceGainsContext {
            var gains : AVCaptureWhiteBalanceGains? = nil
            newValue.getValue(&gains)
            if let g = gains {
                temperatureValue = Double(videoDevice.temperatureAndTintValues(forDeviceWhiteBalanceGains: g).temperature)
            }
        }
    }
}

但它永远不会通过if let g = gains,因为gains是零。甚至更奇怪的是,当我在该行上设置断点时,调试窗口显示gains不是nil且有效但在控制台po gains中输出nil并且代码永远不会通过条件

0 个答案:

没有答案