迅速观察(_:options:changeHandler :) newValue总是为零

时间:2019-10-29 11:30:31

标签: ios swift avfoundation key-value-observing avcapturedevice

我具有此设置来观察AVCaptureDevice deviceWhiteBalanceGains的值更改:

@objc dynamic var videoDevice:AVCaptureDevice?
private var deviceWBGainsObservation: NSKeyValueObservation?

然后在代码中,

deviceWBGainsObservation = videoDevice?.observe(\.deviceWhiteBalanceGains,
                     options: [.old, .new]) {[unowned self] (object, change) in

    NSLog("\(change)")
}

问题是更改oldValue,而newValue始终为nil。如果我使用传统的键值观察方法observeValue(forKeypath:...),则不是这种情况。我在做什么错了?

0 个答案:

没有答案