我正在使用導演,從一個場景移到另一個場景。我有一個問題,即移動到任何場景時,來自Intor的按鈕和文本字段仍然位於屏幕的頂部。corona sdk - scene keep old items
如何在移動到下一個場景之前刪除項目(文本字段,來自intro.lua屏幕的btns)?
enter code here
-- into.lua
module(..., package.seeall)
function new()
--
-- Project: NativeKeyboard2
--
local widget = require("widget")
require("hijacks")
local tHeight -- forward reference
-------------------------------------------
-- General event handler for fields
-------------------------------------------
-- You could also assign different handlers for each textfield
local function fieldHandler(textField)
return function(event)
if ("began" == event.phase) then
-- This is the "keyboard has appeared" event
-- In some cases you may want to adjust the interface when the keyboard appears.
elseif ("ended" == event.phase) then
-- This event is called when the user stops editing a field: for example, when they touch a different field
elseif ("editing" == event.phase) then
elseif ("submitted" == event.phase) then
-- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard
print(textField().text)
-- Hide keyboard
native.setKeyboardFocus(nil)
end
end
end
-- Predefine local objects for use later
local nameField, phoneField
local fields = display.newGroup()
-------------------------------------------
-- *** Create native input textfields ***
-------------------------------------------
-- Note: currently this feature works in device builds or Xcode simulator builds only (also works on Corona Mac Simulator)
local isAndroid = "Android" == system.getInfo("platformName")
local inputFontSize = 18
local inputFontHeight = 30
tHeight = 30
if isAndroid then
-- Android text fields have more chrome. It's either make them bigger, or make the font smaller.
-- We'll do both
inputFontSize = 14
inputFontHeight = 42
tHeight = 40
end
nameField = native.newTextField(40, 120, 200, tHeight)
nameField.font = native.newFont(native.systemFontBold, inputFontSize)
nameField:addEventListener("userInput", fieldHandler(function() return nameField end))
phoneField = native.newTextField(40, 160, 200, tHeight)
phoneField.font = native.newFont(native.systemFontBold, inputFontSize)
phoneField.inputType = "phone"
phoneField:addEventListener("userInput", fieldHandler(function() return phoneField end))
-- Add fields to our new group
fields:insert(nameField)
fields:insert(phoneField)
-------------------------------------------
-- *** Add field labels ***
-------------------------------------------
local defaultLabel = display.newText("الاسم", 250, 120, native.systemFont, 18)
defaultLabel:setTextColor(255, 0, 0)
local defaultLabel = display.newText("رقم الجوال", 250, 160, native.systemFont, 18)
defaultLabel:setTextColor(255, 0, 0)
-- -------------------------------------------
-- -- Create a Background touch event
-- -------------------------------------------
local listener = function(event)
-- Hide keyboard
print("tap pressed")
native.setKeyboardFocus(nil)
return true
end
-- Determine if running on Corona Simulator
--
local isSimulator = "simulator" == system.getInfo("environment")
if system.getInfo("platformName") == "Mac OS X" then isSimulator = false; end
-- Native Text Fields not supported on Simulator
--
if isSimulator then
msg = display.newText("الرجاء ادخال اسمك ورقم جوالك", 0, 280, native.systemFontBold, 12)
msg.x = display.contentWidth/2 -- center title
msg:setTextColor(255,0,0)
end
-- -- Add listener to background for user "tap"
-- bkgd:addEventListener("tap", listener)
-- display.remove(obj)
-- obj = nil
local introGroup = display.newGroup();
local background = display.newImage("graphics/intro_background.png")
local begin = display.newImage("graphics/begin_button.png")
begin.x = 160;
begin.y = 400;
begin.scene = "menu";
introGroup:insert(background);
introGroup:insert(begin);
begin:addEventListener("touch", changeScene)
return introGroup;
end
感謝您的回覆 – malbar