Corona的showOverlay不会第二次出现。

我在我的 showOverlay 函数中遇到了问题。在我的 scene2 中,我有一个按钮点击事件,显示 'composer.showOverlay()',它确实显示了覆盖层,但是当我试图第二次打开它时,在使用 'hideOverlay()' 进行关闭后,它就不起作用了。我必须先回到 scene1,然后再到 scene2 才能再次显示覆盖层。我不知道我的代码哪里出了问题,我谷歌了一下,所有的代码都与我的类似。

以下是代码:

scene2.lua,用于 showOverlay 的按钮

local function reminderBtn( event )
-- 覆盖层场景
local sceneOverlayOptions =
{

    time = 100,
    effect = "slideLeft",
    -- 将参数传递给下一个场景
    params = { result = "覆盖层示例" },
    isModal = true
}
-- 在reminderBtn上按下之后显示覆盖层场景
composer.showOverlay( "sceneOverlay", sceneOverlayOptions)
return true
end

local tabButtons =
{
    {
        id = "tab1",
        width = 32,
        height = 32,
        defaultFile = "images/Alarm_Clock-32.png",
        overFile = "images/Alarm_Clock-32.png",
        labelYOffset = -1,
        onPress = reminderBtn,
    },
    {
        id = "tab2",
        width = 32,
        height = 32,
        defaultFile = "images/Checked-32.png",
        overFile = "images/Checked-32.png",
        labelYOffset = -1,
        onPress = homeBtn,
    },
    {
        id = "tab3",
        width = 32,
        height = 32,
        defaultFile = "images/Image_File-32.png",
        overFile = "images/Image_File-32.png",
        labelYOffset = -1,
        onPress = test,
    }
}

local tabBar = widget.newTabBar
{
    top = display.contentHeight - 40,
    width = display.contentWidth,
    buttons = tabButtons,
}

sceneGroup:insert( tabBar )

sceneOverlay.lua

-- 当按下 hideOverlayBtn 按钮时执行的函数
local function goBack( event )
if (event.phase == "ended") then
    composer.hideOverlay( "slideRight", 250)
    return true
end
end

-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view

-- 从 scene2 中获取参数变量
local params = event.params.result

--创建一个矩形(屏幕覆盖层)
local overlayRectangle = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
overlayRectangle.x = display.contentWidth / 2
overlayRectangle.y = display.contentHeight / 2
overlayRectangle:setFillColor( 0.8, 0.80, 0.8)

local hideOverlayBtn = widget.newButton
{
    left = 100,
    top = 200,
    id = "button1",
    label = "返回",
    onEvent = goBack
}
hideOverlayBtn.x = display.contentWidth / 2
hideOverlayBtn.y = display.contentHeight / 2

sceneGroup:insert( overlayRectangle )
sceneGroup:insert( hideOverlayBtn )
点赞
用户3893454
用户3893454

我认为这是因为tabButton已经被_selected_选中了。你不能在连续两次中使用tabButton。尝试在sceneOverlay中使用一个按钮,而将tabButton用于在场景之间移动。

2015-10-09 10:34:23