如何在拖动父级时关闭子图层上的拖动?

时间:2014-09-02 21:41:15

标签: framerjs

我有一个大的父图层,边上有几个子行。我想防止在垂直拖动父项时水平拖动行。我的猜测是在draggable = falseTouchStart,但没有运气。

cellHeight = 170
cellWidth = 640
rows = 3

container = new Layer
container.draggable = true
container.draggable.speedX = 0
container.width = cellWidth
container.height = cellHeight * rows
container.on Events.TouchMove, ->
    myLayer.draggable = false

container.on Events.TouchEnd, ->
    container.animate
        properties:
            y: 0
        curve: "spring(500, 40, 20)"


for row in [0..rows-1]
    myLayer = new Layer
        x: 0
        y: cellHeight*row
        width: cellWidth
        height: cellHeight
        backgroundColor: "#FFF"
    myLayer.superLayer = container
    myLayer.style =
        borderBottom: "1px solid black"
    myLayer.draggable = true
    myLayer.draggable.speedY = 0
    myLayer.on Events.TouchStart, ->
        container.draggable = false

    myLayer.on Events.TouchEnd, (event, touchedLayer) ->
        container.draggable = true
        touchedLayer.animate
            properties:
                x: 0
            curve: "spring(700, 40, 20)"

1 个答案:

答案 0 :(得分:0)

我测试了你的脚本。 您是否试图阻止在拖动孩子的同时移动父母? 您可以在for循环中尝试此操作:

myLayer.on Events.DragMove, ->
    container.draggable.enabled = false
myLayer.on Events.DragEnd, ->
    container.draggable.enabled = true