用于CALayer动画的SpringWithDamping? [英] SpringWithDamping for CALayer animations?
问题描述
在使用iOS 7中引入的 UIView
动态动画进行了大量游戏后,最值得注意的是:
After playing around a lot with the UIView
dynamic animations introduced in iOS 7, most notably:
[UIView animateWithDuration: delay: usingSpringWithDamping: initialSpringVelocity: options: animations: completion:];
我想知道是否存在可以直接访问的'SpringWithDamping / Velocity'方法创建 CALayer
动画?即要么通过 CATransaction
, CABasicAnimation
,要么......
I was wondering if there is an equivalent to 'SpringWithDamping/Velocity' method that can be accessed directly when creating a CALayer
animation? I.e. either through CATransaction
, CABasicAnimation
or otherwise...
谢谢
推荐答案
在 iOS9 Apple终于取得了 CASpringAnimation
class public。
in iOS9 Apple finally made the CASpringAnimation
class public.
你可以这样使用它:
let spring = CASpringAnimation(keyPath: "position.x")
spring.damping = 5
spring.fromValue = myLayer.position.x
spring.toValue = myLayer.position.x + 100.0
spring.duration = spring.settlingDuration
myLayer.addAnimation(spring, forKey: nil)
请注意,您无法设置动画持续时间 - 您需要为 settlingDuration
询问 CASpringAnimation
类(例如多少时间将弹出系统安定下来)然后将其设置为动画的持续时间。
Notice that you cannot set the animation duration - you need to ask the CASpringAnimation
class for the settlingDuration
(e.g. "How much time is going to take for the spring system to settle down") and then set it as the duration of your animation.
检查 CASpringAnimation
- 它暴露了一些你可以调整的弹簧系统变量 - 刚度,质量等。
Check the header files for CASpringAnimation
- it exposes a number of spring system variables you can adjust - stiffness, mass, etc.
这篇关于用于CALayer动画的SpringWithDamping?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!