–
– Abstract: Tab Bar sample app
– Version: 1.0
– Demonstrates how to create a tab bar that allows the user to navigate between screens,
– using the View Controller Library, viewController.lua.
–import external classes
local ui = require(“ui”)
local viewController = require(“viewController”)
local mainView, tabView, currentScreen, tabBar
local function loadScreen(newScreen)
if currentScreen then
currentScreen:cleanUp()
end
currentScreen = require(newScreen).new()
tabView:insert(currentScreen)
return true
end
local function showScreen(event)
local t = event.target
local phase = event.phase
if phase == “ended” then
if t.id == 1 then
loadScreen(“menu”)
elseif t.id == 2 then
loadScreen(“screen2”)
elseif t.id == 3 then
loadScreen(“screen3”)
elseif t.id == 4 then
loadScreen(“intro”)
end
tabBar.selected(t)
end
return true
end
local function init()
–Create a group that contains the entire screen and tab bar
mainView = display.newGroup()
–Create a group that contains the screens beneath the tab bar
tabView = display.newGroup()
mainView:insert(tabView)
loadScreen(“intro”)
tabBar = viewController.newTabBar{
background = “tabBar.png”, --tab bar background
tabs = {“Play”, “News”, “About”}, --names to appear under each tab icon
onRelease = showScreen --function to execute when pressed
}
mainView:insert(tabBar)
tabBar.selected()
return true
end
function changeScene (e)
if(e.phase == “ended”) then
director:changeScene(e.target.scene)
end
end
local director = require(“director”);
local mainGroup = display.newGroup();
mainGroup:insert(director.directorView);
–Start the program!
init() [import]uid: 155890 topic_id: 29364 reply_id: 118014[/import]