[英]Key value observing exposureDuration
我正在構建一個相機應用程序,我正在嘗試向用戶公開當前的曝光持續時間。 由於此值經常更改,直到手動設置,我需要使用kvo將值流式傳輸給用戶。 我已成功使用ISO
完成此操作,並且可以觀察到exposureDuration
更改,但無法將新值強制轉換為CMTime
對象(這就是exposureDuration的CMTime
)。 下面是我用來嘗試完成此操作的代碼:
override init() {
super.init()
captureDevice = self.selectCamera()
captureDevice?.addObserver(self, forKeyPath: "ISO", options: .New, context: &isoContext)
captureDevice?.addObserver(self, forKeyPath: "exposureDuration", options: .New, context: &shutterContext)
}
deinit {
captureDevice?.removeObserver(self, forKeyPath: "ISO")
captureDevice?.removeObserver(self, forKeyPath: "exposureDuration")
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
let newValue = change?[NSKeyValueChangeNewKey]
if context == &isoContext {
store.iso.value = newValue as! Float
} else if context == &shutterContext {
// The app crashes at this line.
// Thread 1: EXC_BREAKPOINT (code=1, subcode=0x100091670)
// newValue is "AnyObject" in the debug area
store.shutterSpeed.value = newValue as! CMTime
}
}
我做錯了什么,或者這是我需要用蘋果提交的合法錯誤?
exposureDuration的newValue不是CMTime,而是NSValue。 這是固定代碼(swift3)。
store.shutterSpeed.value = (newValue as! NSValue).timeValue
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.