美文网首页
[iOS] CoreAnimation 学习笔记

[iOS] CoreAnimation 学习笔记

作者: BudSwift | 来源:发表于2020-07-05 13:51 被阅读0次

CALayer 隐式动画

隐式动画:属性或内容变化时框架自带的动画效果,即不需要使用类似 UIView Animation 的 API 来触发动画
针对**非 Root Layer **进行支持 animatable 属性的修改会触发隐式动画,比如 backgroundColor, bounds, transform 等等
非 Root Layer:即在 UIView 上手动构建和 add 到 sublayer 的 CALayer
那么相对地,Root Layer 的属性变化仍旧需要手动触发动画。

CALayer 的 position 和 anchorPoint

anchorPoint,是 layer 的锚点,layer 的 position 和 transform 的基准点,范围是 (0, 0)到 (1, 1),
position 是 CALayer 的 anchorPoint 的点在 superLayer 的位置(可以参考 UIView 的 center 属性)

UIImageView 和 UILabel 的 layer

  • Image 是通过 CGImageRef 复制给 imageView.layer.contents 来实现的,即没有一个 ImageLayer 的存在。
    单纯地设置 layer.cornerRadius 无法实现倒角效果,需要使用 layer.masksToBounds = YES。
  • 而 UILabel 则不同,可以通过 [UILabel layerClass] 得知其使用 _UILabelLayer 进行渲染

CoreAnimation 的执行线程

后台线程,不会阻塞主线程。

CAKeyFrameAnimation

支持传 CGBezierPath 进行指定特定参数的路径,比如 position 作为 keyPath

CAAnimation 遵循了 NSCopying 协议

意味着在执行动画时是对传入的动画进行 copy 后使用

CAAnimation 与 UIViewAnimation 的区别

  • CoreAnimation 并不会改变图层的属性值,UIViewAnimation 会修改真实的图层属性
  • 不需要与用户交互时可直接使用 CoreAnimation

相关文章

网友评论

      本文标题:[iOS] CoreAnimation 学习笔记

      本文链接:https://www.haomeiwen.com/subject/uilvqktx.html