我的showOverlay功能有问题。在我的scene2中,我有一个单击按钮,显示'composer.showOverlay()',它确实显示了叠加层,但当我尝试再次打开它时,在用'hideOverlay()'关闭它之后,它什么也没做。我首先要回到scene1然后再回到scene2再次显示叠加层。我不知道我的代码在哪里出错了,我用谷歌搜索,并且所有的代码都与我的代码类似。
这里是代码:
scene2.lua,showOverlay()按钮
local function reminderBtn( event )
-- OVERLAY SCENE
local sceneOverlayOptions =
{
time = 100,
effect = "slideLeft",
-- PASS PARAM VAR TO NEXT SCENE
params = { result = "Overlay Example" },
isModal = true
}
-- SHOW OVERLAY SCENE AFTER PRESS ON 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
-- FUNCTION FOR WHENEVER hideOverlayBtn IS PRESSED
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
-- GET PARAM VAR FOM SCENE 2
local params = event.params.result
--CREATE A RECTANGLE (SCREEN OVERLAY)
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 = "Back",
onEvent = goBack
}
hideOverlayBtn.x = display.contentWidth / 2
hideOverlayBtn.y = display.contentHeight / 2
sceneGroup:insert( overlayRectangle )
sceneGroup:insert( hideOverlayBtn )
答案 0 :(得分:0)
我认为那是因为tabButton已经被选中 ..你不能连续两次选项卡tabButton。尝试使用sceneOverlay的按钮..并保持tabButtons在场景之间移动。