各位iOS开发大佬们好:
我是一名Swift+SwiftUI栈的iOS小白,目前还在上大三,最近准备实习,面试的过程中发现现在大公司很多还在用OC + UIKit的技术栈,OC我还在考虑要不要学,目前想先把UIKit学完,这是我在官网学习UIKit英文文档时摘录的本人认为的重点,如果你们也觉得对你们有用的话欢迎持续关注,我大概一天更一节,有事除外。格式什么的我也就不做了,翻译都是我自己翻译的,哪里不对欢迎在评论区指正,感谢各位大佬支持
今天2021年12月10日
这一章叫做Key-Value Coding Extensions
这章是附录,关于KVC的
Core Animaiton对KVO做了扩展
CAAnimation和CALAyer类是符合键值编码的容器类,这意味着您可以为任意键设置值。即使key someKey 不是 CALayer 类的声明属性,仍可按如下方式为其设置值:
layer.setValue(50,forKey:”someKey”)
取值一样
CAAnimation和CALayer类通过defaultValueForKey: 类方法设置默认值
Kvc支持结构体
CATransform3D Key Paths
You can use the enhanced key path support to retrieve specific transformation values for a property that contains a CATransform3D data type. To specify the full key path for a layer’s transforms, you would use the string value transform or sublayerTransform followed by one of the field key paths in Table C-2.

Setting values using key paths is not the same as setting them using Objective-C properties. You cannot use property notation to set transform values. You must use the setValue:forKeyPath: method with the preceding key path strings.
CGPoint Key Paths
If the value of a given property is a CGPoint data type, you can append one of the field names in Table C-3 to the property to get or set that value.

CGSize Key Paths
If the value of a given property is a CGSize data type, you can append one of the field names in Table C-4 to the property to get or set that value.
Table C-4 CGSize data structure fields

CGRect Key Paths
If the value of a given property is a CGRect data type, you can append the following field names in Table C-3 to the property to get or set that value. For example, to change the width component of a layer’s bounds property, you could write to the key path bounds.size.width.
Table C-5 CGRect data structure fields

这篇博客是针对SwiftUI开发者的一份学习笔记,主要讨论了Objective-C中的Key-Value Coding(KVC)如何在CoreAnimation中得到扩展。作者指出,虽然大公司可能仍在使用OC+UIKit,但SwiftUI开发者也需要理解KVC,因为它是UIKit的重要部分。文中详细介绍了如何在CAAnimation和CALayer类中使用KVC来设置和获取值,包括结构体支持、CATransform3D、CGPoint、CGSize和CGRect的键路径操作。博客还提供了具体的代码示例和关键路径的使用方法。

被折叠的 条评论
为什么被折叠?



