在这里编码:
[self.textView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];
观测方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"change %@", change);
}
每次我在 textView 中输入单词时,即使内容大小没有变化,也会调用该方法。而且在iOS7中没有问题。
什么可能导致此问题?这是UIKit中的一个错误?
试试这个,
[self.textView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew) context:@"mycontext"];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSString *oldValue = [change objectForKey:NSKeyValueChangeOldKey];
NSString *newValue = [change objectForKey:NSKeyValueChangeNewKey];
NSLog(@"OldValue %@",oldValue);
NSLog(@"NewValue %@",newValue);
}