我有以下KVO观察员:
var resizable: JQueryUI.Resizable = $('selector').resizable({ ... });
打印出来:
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if context == &kvoContext {
if (keyPath == "transform") {
if let transform = change![NSKeyValueChangeNewKey] {
print("transform: \(transform)")
overlay.transform = transform as! CGAffineTransform
}
}
}
}
但是,在我的变量窗口中,我将transform: CGAffineTransform: {{1, 0, 0, 1}, {0, 0}}
视为NSConcreteValue:
我在最后一行尝试设置transform
时崩溃了:
overlay.transform
如何检索该值?
答案 0 :(得分:1)
您的转换会自动装入NSValue
对象。您需要像
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if context == &kvoContext {
if (keyPath == "transform") {
if let transform = change?[NSKeyValueChangeNewKey] as? NSValue {
overlay.transform = transform.CGAffineTransformValue()
}
}
}
}