Align

The Align functions help you quickly position an object on the screen relative to its parent. Use these to place a Layer to the top, bottom, left, right or center of its parent. They can be used as layer properties, in states and animations.
译:Align函数帮助你迅速地把一个元素相对于它的父级摆放好位置。使用它们把一个图层放置在它的父级的上下左右或中间。它可以用在属性、状态或者动画中。

# Create a layer an position it in the center
layerA = new Layer
    x: Align.center
    y: Align.center

# Create a state in the bottom right corner 
layerA.states.add
    a:
        x: Align.right
        y: Align.bottom
    b:
        x: Align.left
        y: Align.top

layerA.onTap -> layerA.states.next()

The Align functions calculate the correct value for x or y dynamically at the moment you actually want to position them. So if you have a state that puts a layer in the bottom right position, it will always do so, even if you resize the screen in between switching states.
译:当你需要某个元素的坐标值的时候,Align函数可以动态地计算出它的坐标值。当你在某个状态把一个元素放在右下角,Align函数也可以计算,除非你在转换状态时改变了窗口大小。

You can also optionally use offsets:
译:你也可以选择性地使用偏移量。

layerA = new Layer
    x: Align.center(-100) # 100 pixels left from the center 
    y: Align.top(100) # 100 pixels from the top

Please note that left and right only work for the x property, and top and bottom only for the y property. Center works for both. Align is a flexible more alternative to layer.center() that works well with Auto-Code direct editing.
译: 需要注意的是left和right只对x值起作用,top和bottom只对y值起作用,center对他们都起作用。在直接编程时,对比于layer.center() Align是一个更好的选择,因为它可以自适应。

results matching ""

    No results matching ""