在电晕触摸监听器中,您有 3 个状态:
function listener(event)
if event.phase == "began" then
-- in the 1st tap the phase will be "began"
elseif event.phase == "moved" then
-- after began phase when the listener will be called with moved phase,like touched coordinates
elseif event.phase == "ended" then
--when the touch will end
end
end
nextButton:addEventListener("touch", listener)
--[[这是一个简单的图像触摸监听器,自制按钮等,顺便说一句,当你需要你的按钮时,使用 ui 库正是为此 http://developer.coronalabs.com/code/enhanced -ui-library-uilua ]]
-- example for usage
local ui = require "ui" -- copy the ui.lua to your apps root directory
yourButton = ui.newButton{
defaultSrc = "menu/icon-back.png",--unpressed state image
x=85,
y=display.contentHeight-50,
defaultX = 110,
defaultY =80,
offset=-5,
overSrc = "menu/icon-back-2.png",--pressed state image
overX = 110,
overY = 80,
onEvent = buttonhandler,
id = "yourBtnId" -- what you want
}
local function buttonhandler(event)
if event.phase == "release" then
--if you have more buttons handle it whit they id-s
if event.id == "yourBtnId" then
-- when your button was finally released (like in 1st example ended, but this will be called only if the release target is your button)
end
end
end