观察者模式的使用步骤分为三步:
1 设置观察者:addObserver: forKeyPath: options:NSKeyValueObservingOptionNew context:
2 实现kvo方法:- (void)observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable id)object change:(nullable NSDictionary<NSString *,id> *)change context:(nullable void *)contex
3 移除kvo观察:
- (void)dealloc{
[ ...removeObserver:self forKeyPath:@"contentOffset"];
}