2013-06-12 1 views
0

이미지가 특정 위치에 선언되어 있습니다.Tap의 이미지에 대한 애니메이션 드롭 다운

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) 
+0

동시에 또는 두 가지 모두 '페이드 아웃에서'드롭 다운 '또는 필요하다고 지정하세요 .. . –

+0

동시에 둘 다. 나는 당신의 응답에 아래에 응답했다. – Vikr

답변

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 매개 변수를 제거 할 수 있습니다.

............... 코딩 유지 :

+0

krs, 도움 주셔서 감사합니다. 코드가 작동하지만 문제가 있습니다. 첫 번째 이미지를 아주 빨리 클릭하면 .. 첫 번째 이미지를 다시 클릭하면 두 번째 이미지가 표시되고 페이드 아웃/숨김이 발생합니다 .. – Vikr

+0

@Vikr : 코드를 수정했습니다 ... –

관련 문제