0

我在某个特定位置声明了一张图片。

local deselectButton = display.newImage ( "images/nutritional info/deselectButton.png" )
deselectButton.x = display.contentWidth / 2 - 15
deselectButton.y = display.contentHeight / 2 - 172
deselectButton.id = "0"
nutriinfo:insert(nutriNavBar)

当我点击该图像时,我希望显示另一张图像。也就是说,每次我点击上面的图片时,第二张图片都应该淡入淡出。

local dropDown1 = display.newImage ( "images/nutritional info/dropDown.png" )
dropDown1.x = display.contentWidth / 2 - 75
dropDown1.y = display.contentHeight / 2 - 65
dropDown1:setReferencePoint(display.TopCenterReferencePoint)
4

1 回答 1

2

在您的代码之后,只需执行以下操作......这可能会对您有所帮助:

local function addListener()
  deselectButton:addEventListener("tap",clickFunction)
end

local clickCount = 0
function clickFunction()
  deselectButton:removeEventListener("tap",clickFunction)
  clickCount = clickCount + 1
  if(clickCount%2==1)then
     -- show the image
     transition.to(dropDown1,{time=200,x=dropDown1.x,y=dropDown1.y+100,alpha=1,onComplete=addListener}) -- or parameters as you like
  else
     -- hide the image
     transition.to(dropDown1,{time=200,x=dropDown1.x,y=dropDown1.y-100,alpha=0,onComplete=addListener})
  end
end
deselectButton:addEventListener("tap",clickFunction)

注意:上面的代码为您提供了下拉和淡入/淡出效果。但是,如果你只需要淡入淡出效果,你可以y从过渡中去掉参数,如果你想要下拉式的效果,你可以去掉alpha参数。

继续编码...... :)

于 2013-06-12T18:41:44.303 回答