任何人都可以在CALayer中解释内容属性中可动画的内容吗?它是如何动画的?

问题描述 投票:-3回答:1

我正在学习核心动画。但我在解释中看到一个可动画的单词。请解释。 https://developer.apple.com/documentation/quartzcore/calayer/1410773-contents

ios core-animation
1个回答
1
投票

对于CALayer属性,它只是意味着those "animatable" properties可以通过Core Animation(例如CABasicAnimation)进行动画制作。例如,这会将backgroundColorCALayer属性(可动画)从任何时候转换为.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,如上所示。

© www.soinside.com 2019 - 2024. All rights reserved.