一、CALayer官方文档

Layers are often used to provide the backing store for views but can also be used without a view to display content. A layer’s main job is to manage the visual content that you provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow. In addition to managing visual content, the layer also maintains information about the geometry of its content (such as its position, size, and transform) that is used to present that content onscreen. Modifying the properties of the layer is how you initiate animations on the layer’s content or geometry. A layer object encapsulates the duration and pacing of a layer and its animations by adopting the CAMediaTiming protocol, which defines the layer’s timing information.

If the layer object was created by a view, the view typically assigns itself as the layer’s delegate automatically, and you should not change that relationship. For layers you create yourself, you can assign a delegate object and use that object to provide the contents of the layer dynamically and perform other tasks. A layer may also have a layout manager object (assigned to the layoutManager property) to manage the layout of subviews separately.

二、UIView和CALayer的关系

由官方文档和平时的知识积累和开发经验可知,Layer是View的一个属性,Layer由View初始化时自动创建,而且View会自动将自己设置为Layer的代理。

同时CALayer提供了一个+layerClass方法,我们可以通过重写这个方法返回一个我们自定义的CALayer的子类的类型,这时,UIView会自动创建一个我们自定义子类类型的Layer作为View的根Layer。

+ (Class)layerClass;

三、CALayer的一些属性

1 presentationLayer

通过官方文档可知,Layer的作用是为View提供后备存储,什么意思呢?Layer的主要工作是提供视觉内容,当我们修改Layer的属性时,会启动隐式动画,动画是有过渡时间的。如果一个动画还没有结束,我们提交了新的属性,这时会发生什么?会在前一个动画结束后,才会刷新新的属性。也就是说Layer的属性不是实时显示在屏幕上的,那么我们怎样获取此时屏幕上属性值呢?

可查看官方文档中对presentationLayer的描述,这个值是最接近此时屏幕显示的属性值的Layer。

2 contents

The default value of this property is nil.

If you are using the layer to display a static image, you can set this property to the CGImage containing the image you want to display. (In macOS 10.6 and later, you can also set the property to an NSImage object.) Assigning a value to this property causes the layer to use your image rather than create a separate backing store.

当我们把这个值设置为一个CGImage对象时,Layer就会显示为一张图片。

3 display

这个方法不要主动调用,通过调用Layer的代理的display(_:)方法或者Layer的draw(in:) 方法,会自动调用改方法。这个方法的作用是设置contents属性。我们可以重写这个方法,来设置自定义的contents。

4 setNeedsDisplay

Marks that -display needs to be called before the layer is next committed.

从Xcode的接口声明中可以指导,该方法不会立即调用display方法,而是做一个标记,在Layer下一次提交时,先调用display方法。

5 defaultValue(forKey:)

指定默认属性值。

四、总结

我们了解了以上几个属性和方法的作用,就能轻松的知道YYtext的同步/异步渲染流程了。

layer 同步调用_YYText源码解读-YYText同步/异步渲染流程(一)—UIView与CALayer相关推荐

  1. pyecharts源码解读(10)渲染包render之templates目录:渲染模板

    当前pyecharts版本为1.9.0 概述 render包结构 render包位于pyecharts包顶级目录中,用于渲染图表.render包结构如下: ├─render # 渲染设置包 │ │ d ...

  2. mysql lenenc int_MySQL-NonMySQL同步工具源码解读——确定同步位置

    经过上一节的鉴权过后,程序已经受主库认可,并且可以像主库发起同步请求.在发起请求之前,还有一个可选的步骤:确认同步时间点.同步时间点由两个属性进行标识:Binlog文件名.偏移量.工具支持自定义时间点 ...

  3. datax 定时执行多个job_数据同步神器Datax源码重构

    每日一句永远不要认为我们可以逃避, 我们的每一步都决定着最后的结局, 我们的脚步正在走向我们自己选定的终点.Do not ever think about that we can escape , o ...

  4. faster rcnn源码解读(五)之layer(网络里的input-data)

    转载自:faster rcnn源码解读(五)之layer(网络里的input-data) - 野孩子的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/u010668 ...

  5. Redis 源码解读之 Rehash 的调用时机

    Redis 源码解读之 Rehash 的调用时机 背景和问题 本文想要解决的问题 什么时机触发 Rehash 操作? 什么时机实际执行 Rehash 函数? 结论 什么时机触发 Rehash 操作? ...

  6. PyTorch 源码解读之 cpp_extension:讲解 C++/CUDA 算子实现和调用全流程

    "Python 用户友好却运行效率低","C++ 运行效率较高,但实现一个功能代码量会远大于 Python".平常学习工作中你是否常听到类似的说法?在 Pyth ...

  7. ios html zfplayer,【iOS】ZFPlayer源码解读中

    前言 本篇继ZFPlayer源码解读基础之上,主要解析说明控制层与播放器,因为在上篇文章至现在并未提及丝毫关于这两个类业务的实现. 首先说下这两个类各自的职责. 控制层:主要负责响应与用户之间的交互, ...

  8. Bert系列(二)——源码解读之模型主体

    本篇文章主要是解读模型主体代码modeling.py.在阅读这篇文章之前希望读者们对bert的相关理论有一定的了解,尤其是transformer的结构原理,网上的资料很多,本文内容对原理部分就不做过多 ...

  9. Java Review - Queue和Stack 源码解读

    文章目录 Pre 概述 Queue Deque ArrayDeque 一览 构造函数 属性 方法 addFirst() addLast() pollFirst() pollLast() peekFir ...

最新文章

  1. Python基础-安装
  2. IOS开发之NSObject协议类方法说明
  3. hadoop配置文件详解系列(二)-hdfs-site.xml篇
  4. html怎么消除打印的进纸,打印机缺纸状态怎么消除?
  5. 字符串大小写互换方法
  6. 5月份Github上最热门的数据科学和机器学习项目
  7. python如何读取数据保存为新格式_python,初学者应用实例:读取文件中的数据,将将北京时间转换成世界时间,再保存成新的CSV格式文件...
  8. linux的tcpdump命令详解,tcpdump命令
  9. SurfaceGo使用体验(使用半年后)
  10. Zookeeper Curator API 使用
  11. 郑州轻工业学校计算机网络,计算机网络期末考试a卷(郑州轻工业学院).doc
  12. Ubuntu20.04 在anaconda上,opencv-python支持h264编码
  13. NX1957在VS2019上二次开发的环境配置
  14. 一、 WIN32程序
  15. 跨平台音视频jQuery插件:jPlayer
  16. 3735平板装win和linux双系统,流行的就一定好?浅谈双系统平板的利与弊
  17. 查看Debian版本号的方法
  18. XMLSchema 注解
  19. 2022 学术英语写作(东南大学) 最新Unit 1章节测试答案
  20. 19美亚个人赛复盘2(手机取证)

热门文章

  1. hdfs集成ldap
  2. Docker : Docker 安装ES
  3. 【Docker】Error: No such image: gotok8s/kube-proxy:v1.16.5
  4. 【Hbase】 Region Server 各种意外退出
  5. HDFS数据管理与容错
  6. Cloud Native的设计哲学理念,kubernetes云生态操作系统
  7. android 分析so崩溃,分析libunity.so Release崩溃
  8. SQLServer之深度分析跟踪
  9. 找不到可安装的isam怎么解决_安装系统找不到硬盘怎么办
  10. github语音识别对对_语音识别尝试方向