自定义CALayer在CAAnimation过程中自定义property为nil问题

问题:
自定义CALayer在CAAnimation过程中自定义property为nil。

原因:
CA框架维护着三套Layer tree,这个在CAAnimation Guide中有说,可惜我忘了

layer tree中存储着最终的结果值 last value,presentation tree只有在CAAnimation动画 on-flight就是进行过程中才可访问,其中值是当前变化中的值current -value,而render tree是CA框架私有维护的,任何时候不可访问。

所以
When you add an animation to a CALayer,it creates a so-called presentation copy of that layer using initWithLayer:. The presentation layer contains actual animated state for each animation frame,while the original layer has the final state. The problem with animating your own properties is that CALayer does not copy them all in initWithLayer:. If that’s your case,your should override initWithLayer: and set up all the properties you need for animation。

当CALayer加入一个动画对象时,其实是复制了一份CALayer到presentation tree中去做动画效果,在这个过程中如果你没有override initWithLayer函数的话,这些自定义元素在复制过程中就没有被初始化,就成为了nil。 所以override initWithLayer中复制这些property给新的拷贝实例即可。

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...