How reliable is KVO with UIKit(使用 UIKit 的 KVO 有多可靠)
问题描述
重要提示:并非所有课程都是所有属性都符合 KVO.你可以确保您自己的课程是按照以下步骤符合 KVOKVO 合规性"中描述.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.
这句话让我很困惑.我们不能对 UIKit 对象使用 KVO 吗?我不记得看到任何属性被记录为符合 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
属性保持不变,因此不会为 view.bounds
路径触发观察者,因为它永远不会真正改变.这会导致不符合 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.
这篇关于使用 UIKit 的 KVO 有多可靠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 UIKit 的 KVO 有多可靠


- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01