Animation
Animation objects manage animations that target a layer and properties. An animation will tween between a start and end value, with a curve. The start value is determined when the animation starts, and the end value is defined by properties. If the start values equal to end values, they won't animate.
译:动画对象用来管理图层或者属性的动画。一个动画就是某个属性在起始值和结束值之间以一种运动曲线过渡。在动画开始时那些属性默认的值就是起始值,我们需要定义一下属性的结束值。如果它们相等就不会有动画效果。
Properties(属性值)
layer— 一个要被触发动画的图层对象.properties— 该动画最终的一些属性值对象.curve— 一个字符串,默认是“ease”。(可选的)curveOptions— 带有运动曲线属性值的对象. (可选的)time— 数字,代表动画运行多少秒. (可选的)delay— 数字,动画延迟执行的时间 (可选的)repeat— 数字, 动画重复的次数 (可选的)colorModel— 字符串, 动画变幻时的颜色模式。(可选的)
Example: layer and properties(示例: 图层和属性变化)
Here, we create a new Animation for layerA. Once we start the animation, it will move horizontally from 0 to 100. Note that we left out many optional arguments. By default, the animation will take 1 second, with a ease curve.
译:这里我们给layerA设置一个新的动画。动画开始后这个图层就会从0水平移动到100.需要注意的是,有很多可选的动画参数我们没有写,那么这个动画就默认执行1秒,使用ease曲线。
layerA = new Layer
# Animate the layer to the right
animationA = new Animation
layer: layerA
properties:
x: 100
Example: multiple properties and time(示例: 多属性变化和动画时间)
Multiple properties can be animated at once. Here, we animate the x and opacity properties, with a duration of 5 seconds.
译:我们可以对多个属性同时执行动画。下面的代码就是在5秒内让图层的x坐标和透明度同时变化。
layerA = new Layer
# Animate multiple properties for 5 seconds
animationB = new Animation
layer: layerA
properties:
x: 100
opacity: 0.5
time: 5
Example: repeat and delay(示例: 重复和延迟)
When using repeat, the end values of properties will be reset to their starting position instantly. In the example below, there is a 2 second delay between every repeat.
译:当启用重复选项时,动画结束时变化的属性就会立即恢复到开始的状态。下面的例子中,图层的动画每次重复之间会有2秒的延迟。
# Repeat an animation 5 times, delay for 2 seconds
animationD = new Animation
layer: layerA
properties:
x: 100
repeat: 5
delay: 2
Example: ease-in-out(示例: ease-in-out)
Included easing curves are ease-in, ease-out and ease-in-out.
译:动画中已经包含的动画曲线有ease-in, ease-out和ease-in-out。
# Animate with an ease-in-out curve
animationE = new Animation
layer: layerA
properties:
x: 100
curve: "ease-in-out"