鍵值觀察 - KVO
如何使用 KVO
let _observOption:NSKeyValueObservingOptions = NSKeyValueObservingOptions([NSKeyValueObservingOptions.New,NSKeyValueObservingOptions.Old])
mImageView.addObserver(self, forKeyPath: "image", options: _observOption, context: nil)deinit {
mImageView.removeObserver(self, forKeyPath: "image")
}override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if keyPath == "image" {
mLoadingView.stopAnimating()
}
}
Last updated