Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了自定义CALayer在CAAnimation过程中自定义property为nil问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

问题: 自定义CALayer在CAAnimation过程中自定义property为nil。 原因: CA框架维护着三套Layer tree,这个在CAAnimation Guide中有说,可惜我忘了 layer tree中存储着最终的结果值 last value,presentation tree只有在CAAnimation动画 on-flight就是进行过程中才可访问,其中值是当前变化中的值cu

问题:
自定义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给新的拷贝实例即可。

大佬总结

以上是大佬教程为你收集整理的自定义CALayer在CAAnimation过程中自定义property为nil问题全部内容,希望文章能够帮你解决自定义CALayer在CAAnimation过程中自定义property为nil问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。