KVO与UIKit的可靠性如何 [英] How reliable is KVO with UIKit

查看:97
本文介绍了KVO与UIKit的可靠性如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


重要提示:并非所有属性都符合
KVO标准。您可以通过遵循KVO合规性中描述的步骤
来确保您自己的类符合
KVO.
通常,Apple提供的
框架中的属性仅为KVO兼容,如果
他们被记录为这样。

Important: Not all classes are KVO-compliant for all properties. You can ensure your own classes are KVO-compliant by following the steps described in "KVO Compliance." Typically properties in Apple-supplied frameworks are only KVO-compliant if they are documented as such.

这句话让我感到困惑。我们不能将KVO用于UIKit对象吗?我不记得看到任何财产被记录为符合KVO标准。尽管如此,我仍然可以使用具有许多属性的KVO。这是否意味着我不能依赖它?

This statement leaves me confused. Can't we use KVO for UIKit objects at all? I don't remember seeing any property being documented as KVO compliant. Despite saying otherwise, I am able to use KVO with many properties. Does this mean that I can't rely on it?

任何对此的见解都将受到赞赏。

Any insight into this would be appreciated.

推荐答案

UIKit大多不符合KVO标准。这主要是因为 UIView 充当 CALayer 的高级包装器,所以当你这样做时。更改 UIView frame 属性,它将更改图层 frame 但请留下例如。 UIView bounds 属性未触及,因此视图不会触发任何观察者。 bounds path,因为它永远不会真正改变。这导致非KVO合规。

UIKit is mostly NOT KVO compliant. This is mostly because UIView acts as high-level wrapper for CALayer, so when you eg. change the frame property of an UIView, it will change the layers frame but leave eg. the bounds property of the UIView untouched, so no observer will be triggered for the view.bounds path, because it never really changes. And this leads to non KVO compliance.

只有当该属性被标记为符合KVO时才能依赖于此,否则它将无法工作或在某些奇怪的情况下中断。

Only if the property is marked as KVO compliant can you rely on this, otherwise it will not work or break in some weird cases.

这篇关于KVO与UIKit的可靠性如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆