我正在尝试监视 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 设置为简单的“框架”,则不会出现错误,但不会调用 observeValueForKeyPath 方法。我猜对框架原点的更改不算作对框架的更改..?
如何完成将观察者添加到 UIView 的 frame.origin.y ?