gpt4 book ai didi

iOS:将观察者添加到 UIView 的 frame.origin.y?

转载 作者:技术小花猫 更新时间:2023-10-29 10:46:19 34 4
gpt4 key购买 nike

我正在尝试监视 UIView 框架原点的变化值并使用react。我的代码:

[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 永远不会被调用。我想对框架原点的更改不算作对框架的更改..?

如何将观察者添加到 UIView 的 frame.origin.y ?

最佳答案

虽然我无法完全按照我最初想要的方式解决我的问题,但我发现我能够将观察者正确添加到 UIView 的中心。通过监视 View 中心,我可以确定框架的原点已更改。

[cell.bottomView addObserver:self forKeyPath:@"center" options:NSKeyValueObservingOptionNew context:NULL];

关于iOS:将观察者添加到 UIView 的 frame.origin.y?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17975710/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com