UIImagVIew * coverImage = nil;
/*........
........相关代码.......
........
*/
//为coverImage的image属性添加KVO,添加自己为属性变化的观察者
[coverImage addObserver:self forKeyPath:@"image" options:0 context:nil];
//KVO的回调函数,当keyPath发生变化时调用
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"image"]) {
//如果发生变化,进行相关处理
..........
}
}
- (void)dealloc
{
//移除观察者
[coverImage removeObserver:self forKeyPath:@"image"];
}