0

我有一个很大的父层,旁边有几个子行。我想防止在垂直拖动父级时水平拖动行。我的猜测是继续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)"
4

1 回答 1

0

我已经测试了你的脚本。您是否试图阻止在拖动孩子时移动父母?你可以在你的 for 循环中试试这个:

myLayer.on Events.DragMove, ->
    container.draggable.enabled = false
myLayer.on Events.DragEnd, ->
    container.draggable.enabled = true
于 2015-02-03T03:16:22.360 回答