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:
译:“改变”事件让你听的属性,因为他们正在改变。以下是你可以侦听属性的完整概述:

  1. "change:x" — New x position.
  2. "change:y" — New y position.
  3. "change:point" — New x or y position.
  4. "change:width" — New width value.
  5. "change:height" — New height value.
  6. "change:size" — New width or height values.
  7. "change:frame" — New x, y, width or height values.
  8. "change:scale" — New scale value.
  9. "change:rotation" — New rotation value.
  10. "change:borderRadius" — New borderRadius value.
  11. "change:currentPage" — New currentPage layer.
  12. "change:style" — New style declaration.
  13. "change:html" — New html declaration.
  14. "change:children" — Added or removed children.
  15. "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

results matching ""

    No results matching ""