电晕sdk故事板使用按钮移动下一步

时间:2013-04-16 15:18:26

标签: corona corona-storyboard

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

我的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

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

- 注意:目前此功能仅适用于设备构建或Xcode模拟器构建(也适用于Corona Mac Simulator)     local isAndroid =“Android”== system.getInfo(“platformName”)     本地inputFontSize = 18     本地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 ) ) 

- 将字段添加到我们的新组中     字段:插入(名称字段)     字段:插入件(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

- 本地button1Release =功能(事件)      - 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

- 当场景视图不存在时调用:     功能场景:createScene(事件)         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

- 场景移动到屏幕后立即调用:     功能场景:enterScene(事件)

    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

- 当场景即将移动到屏幕外时调用:     功能场景:exitScene()

    print( "2: exitScene event" )

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

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

- 在删除场景的“视图”(显示组)之前调用     功能场景:destroyScene(事件)

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

- 结束实施

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

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

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

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


return scene it is not  move to next scene..

动作正常,它显示测试消息..

enter code here

0 个答案:

没有答案