我试图监测并对UIView框架的起点值进行反应。我的代码:
[cell.bottomView addObserver:self forKeyPath:@"frame.origin" options:NSKeyValueObservingOptionNew context:NULL];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"%@ Changed", keyPath);
}
我收到了一个我不理解的错误信息:An instance 0x7587d10 of class NSConcreteValue was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0x7587fd0> (
<NSKeyValueObservance 0x7587f70: Observer: 0x7587bd0, Key path: origin, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x7587ff0>
)
实际上,我只对原点的y位置感兴趣,但是如果我将keyPath设置为"frame.origin.y",代码甚至无法编译。
如果我将keyPath简单地设置为"frame",就没有错误,但是observeValueForKeyPath方法从未被调用。我猜改变frame的原点位置不算作对frame的更改..?
如何添加观察者以获取UIView的frame.origin.y值?
observerValueForKeyPath:
方法中没有调用 super。 - pronebird