2014-09-02 48 views
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)" 

回答

0

我測試了你的腳本。 您是否試圖在拖動孩子時阻止父母移動? 你可以在for循環中試試這個:

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