0

我正在使用 director 从一个场景移动到另一个场景。我有一个问题,当移动到任何场景时,来自 intor 的按钮和文本字段仍在屏幕顶部。

如何在移动到下一个场景之前删除项目(文本字段,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
4

1 回答 1

1

Corona 提供了一个非常好的功能,那就是“故事板”。我给你一个简单的解释,试试这个 -

  • Storyboard - 它是一个场景(例如“屏幕”或“视图”)管理库,为开发人员提供了一种在 Corona SDK 应用程序中创建和转换场景模块的简单方法。

    语法 - 本地故事板 = 需要“故事板”

    示例 -
    本地场景 1 = storyboard.newScene(“场景名称”)

    以下是故事板中使用的不同事件 -

    1- 创建场景 -
    -- 当场景的视图不存在时调用:

    功能场景:createScene(事件)本地组= self.view end

    2-进入场景-- 在场景移动到屏幕后立即调用:

    功能场景:enterScene(事件)本地组= self.view end

    3- Exit Scene - -- 当场景即将移出屏幕时调用:

    功能场景:exitScene(事件)本地组= self.view

    结尾

    4 - Destroy Scene - -- 在移除场景的“视图”(显示组)之前调用

    功能场景:destroyScene(事件)本地组= self.view end

它会帮助你。

于 2013-04-16T04:45:25.787 回答