Core Animation学习笔记—第十节Key-Value Coding Extensions

各位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
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Programmer_Roy/article/details/121717625