1

我正在捆绑故事板,我希望用户在填充字段后移动到下一个场景,然后按下按钮

我的 btn 有问题,------------------------------ --------------------------------------

--scence2.lua


local storyboard = require( "storyboard" )
local scene = storyboard.newScene()

-- 开始实施

local widget = require( "widget" )

require("hijacks")
local sysFonts = native.getFontNames()
local tHeight       -- forward reference

local roundedRect = display.newRoundedRect( 40, 120, 200, 40, 8 )
roundedRect:setFillColor( 0, 0, 0, 170 )

local t = display.newText( "Waiting for button event...", 0, 0, "AmericanTypewriter-Bold", 18 )
t.x, t.y = display.contentCenterX, 70

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

-- 预定义本地对象供以后使用 local nameField, phoneField local fields = display.newGroup()

-- 注意:目前此功能仅适用于设备构建或 Xcode 模拟器构建(也适用于 Corona Mac 模拟器) 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 ) ) 

-- 将字段添加到我们的新组 fields:insert(nameField) fields:insert(phoneField)

-- * 添加字段标签 *

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 )

-- 这些是按钮触发的功能

local button1Press = function( event )
    t.text = "Button 1 pressed"
end

local button1Release = function( event )
    t.text = "Button 1 released"
end


local buttonHandler = function( event )
    t.text = "id = " .. event.target.id .. ", phase = " .. event.phase
end

-- 此按钮具有单独的按下和释放功能 -- (如果没有指定字体,标签字体默认为 native.systemFontBold)

local button1 = widget.newButton{
    default = "buttonRed.png",
    over = "buttonRedOver.png",
    onPress = button1Press,
    onRelease = button1Release,
    label = "موافق",
    emboss = true

}

local button2 = widget.newButton{
    default = "buttonBlue.png",
    over = "buttonBlue.png",
    onEvent = buttonHandler,
    onPress = button1Press,
    onRelease = button1Release,
    label = "ok",

    emboss = true;
    labelColor = { default = { 51, 51, 51, 255 } },
    fontSize = 32,

}

button1.x = 160; button1.y = 320

-- 这些是按钮触发的功能

local button1Press = function( event )
        nameField.text = "Button 1 pressed"
        nameField.text = "hello"
    storyboard.gotoScene( true, "scene3", "fade", 800  )
end

-- local button1Release = function( event ) -- nameField.text = "按钮 1 释放"

- 结尾

local funcction buttonHandler = function( event )
-- nameField.text = "hello"
-- storyboard.gotoScene( true, "scene3", "fade", 800  )

    local background = display.newImage("buttonBlue.png", true) -- flag overrides large image downscaling
    background.x = display.contentWidth / 2
    background.y = display.contentHeight / 2
end

local image, text1, text2, text3

local function onSceneTouch( self, event )
    if event.phase == "began" then

    -- first argument means show native activity indicator while transitioning
    --storyboard.gotoScene( true, "scene3", "fade", 800  )



        return true
    end
end

-- 场景视图不存在时调用:function scene:createScene( event ) local screenGroup = self.view

    image = display.newImage( "bg2.jpg" )
    screenGroup:insert( image )

    image.touch = onSceneTouch

    text1 = display.newText( "Scene 2", 0, 0, native.systemFontBold, 24 )
    text1:setTextColor( 255 )
    text1:setReferencePoint( display.CenterReferencePoint )
    text1.x, text1.y = display.contentWidth * 0.5, 270
    screenGroup:insert( text1 )

    text2 = display.newText( "MemUsage: ", 0, 0, native.systemFont, 16 )
    text2:setTextColor( 255 )
    text2:setReferencePoint( display.CenterReferencePoint )
    text2.x, text2.y = display.contentWidth * 0.5, display.contentHeight * 0.5
    screenGroup:insert( text2 )

    text3 = display.newText( "Touch to continue.", 0, 0, native.systemFontBold, 18 )
    text3:setTextColor( 255 ); text3.isVisible = false
    text3:setReferencePoint( display.CenterReferencePoint )
    text3.x, text3.y = display.contentWidth * 0.5, display.contentHeight - 100
    screenGroup:insert( text3 )

    print( "\n2: createScene event" )
end

-- 场景在屏幕上移动后立即调用:function scene:enterScene( event )

    print( "2: enterScene event" )

-- remove previous scene's view
    storyboard.purgeScene( "scene1" )

-- Update Lua memory text display
    local showMem = function()
        image:addEventListener( "touch", image )
        text3.isVisible = true
        text2.text = text2.text .. collectgarbage("count")/1000 .. "MB"
        text2.x = display.contentWidth * 0.5
    end
    local memTimer = timer.performWithDelay( 1000, showMem, 1 )
end

-- 场景即将移出屏幕时调用:函数scene:exitScene()

    print( "2: exitScene event" )

-- remove touch listener for image
    image:removeEventListener( "touch", image )

-- reset label text
    text2.text = "MemUsage: "
end

-- 在移除场景的“视图”(显示组)函数之前调用scene:destroyScene(event)

    print( "((destroying scene 2's view))" )
end

-- 执行结束

-- 如果场景的视图不存在,则调度“createScene”事件 scene:addEventListener("createScene", scene)

-- 只要场景转换完成,就会调度 "enterScene" 事件 scene:addEventListener( "enterScene", scene )

-- "exitScene" 事件在下一个场景的转换开始之前调度 scene:addEventListener("exitScene", scene)

-- "destroyScene" 事件在视图被卸载之前被调度,它可以 -- 在内存不足的情况下自动卸载,或者通过调用 --storyboard.purgeScene() 或 storyboard.removeScene() 显式地卸载。场景:addEventListener(“destroyScene”,场景)


return scene it is not  move to next scene..

该操作工作正常,它显示测试消息..

enter code here
4

0 回答 0