我正在学习核心动画。但我在解释中看到一个可动画的单词。请解释。 https://developer.apple.com/documentation/quartzcore/calayer/1410773-contents
对于CALayer
属性,它只是意味着those "animatable" properties可以通过Core Animation(例如CABasicAnimation
)进行动画制作。例如,这会将backgroundColor
的CALayer
属性(可动画)从任何时候转换为.red
,持续两秒钟:
let animation = CABasicAnimation(keyPath: "backgroundColor")
animation.toValue = UIColor.red.cgColor
animation.duration = 2
view.layer.add(animation, forKey: nil)
有关更多信息,请参阅Core Animation Programming Guide。
我知道你问过CALayer
,但你也看到了关于UIView
属性的“动画”。在这种情况下,它意味着那些可以使用UIViewPropertyAnimator
或较旧的基于块的动画方法(如animate(withDuration:animations:)
)进行动画处理。
在可能的情况下,通常更喜欢动画UIView
属性,而不是CALayer
属性,因为这些UIView
动画技术提供了漂亮的,基于块的再现,并且倾向于更直接地与我们在UIKit中日常使用的内容相对应。但是当需要/需要时,您当然可以潜入CALayer
Core Animation,如上所示。