Change Events
The"change"event allows you to listen to properties as they're changing. Below is a full overview of properties you can listen for:
译:“改变”事件让你听的属性,因为他们正在改变。以下是你可以侦听属性的完整概述:
"change:x"— New x position."change:y"— New y position."change:point"— New x or y position."change:width"— New width value."change:height"— New height value."change:size"— New width or height values."change:frame"— New x, y, width or height values."change:scale"— New scale value."change:rotation"— New rotation value."change:borderRadius"— New borderRadius value."change:currentPage"— New currentPage layer."change:style"— New style declaration."change:html"— New html declaration."change:children"— Added or removed children."change:parent"— Added or removed parent.
For example, you can get the x position of a layer while it's animating. Note that it'll return the exact, sub-pixel values.
译:例如,您可以在它的动画得到层的x位置。需要注意的是,它会返回准确,子像素值。
layerA = new Layer
layerA.animate
properties:
x: 100
layerA.on "change:x", ->
print layerA.x
The "change" events can be used to link property changes to one another, with modulate. In the example below, we'll rotate the layer. The returned values are used to move the second layer horizontally.
译:“改变”事件可以用来属性更改链接到另一个,与调制。在下面的例子中,我们将旋转层。返回的值用于第二层水平移动。
layerA = new Layer
layerB = new Layer
x: 100
# We rotate layerA from 0 to 180 degrees.
layerA.animate
properties:
rotation: 180
# When the rotation value from layerA changes
layerA.on "change:rotation", ->
# Use the values to move layerB from 100 to 300
x = Utils.modulate(layerA.rotation, [0, 180], [100, 300], true)
layerB.x = x