用钛将一个窗口移动到另一个窗口

Moving one window to another in titanium

本文关键字:窗口 一个 移动 另一个      更新时间:2023-09-26

my app.js

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();

//
// create base UI tab and root window
//
var homeWindow = Titanium.UI.createWindow({  
    backgroundColor:'#fff',
    url:'home.js',
    backgroundImage:'appImage/background.png',
    navBarHidden:true
});
var homeTab = Titanium.UI.createTab({  
    icon:'appImage/home.png',
    size:{height:10,width:10},
    title:'Home',
    backgroundColor:'#999',
    window:homeWindow
});

//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff',
    url:'win2.js'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});
//win2.add(label2);
// win3
var win3 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff',
    url:'win3.js'
});
var tab3 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 3',
    window:win3
});

//win3.add(label2);

// win4
var win4 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff',
    url:'win4.js'
});
var tab4 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 4',
    window:win4
});
//win5
var win5 = Titanium.UI.createWindow({  
    title:'Tab 5',
    backgroundColor:'#fff',
    url:'win5.js'
});
var tab5 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 5',
    window:win5
});
//win6
var win6 = Titanium.UI.createWindow({  
    title:'Tab 6',
    backgroundColor:'#fff',
    url:'win6.js'
});
var tab6 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 6',
    window:win6
});

//
//  add tabs
//
tabGroup.addTab(homeTab);  
tabGroup.addTab(tab2);
tabGroup.addTab(tab3);
tabGroup.addTab(tab4);  
tabGroup.addTab(tab5);  
//tabGroup.addTab(tab6);

// open tab group
tabGroup.open();

我的家.js

var txtLogoImage = Ti.UI.createImageView({
  image:'appImage/txtLogo.png',
  height:30,
  width:170,
  top:15,
});
var loginButton = Ti.UI.createButton({
    title: 'Login',
    //image:'appImage/atm.png',
    backgroumdImage:'appImage/buttonbg.png',
    top: 90,
    height:30,
  width:170,
});
loginButton.addEventListener('click',function(event){
    //How can I go to the win2???
});
var atmLocatorButton = Ti.UI.createButton({
    title: 'ATM Locator',
    top: 130,
    height:30,
    width:170
});
var branchLocatorButton = Ti.UI.createButton({
    title: 'Branch Locator',
    top: 170,
    height:30,
    width:170
});

var cityTouchLogoImage = Ti.UI.createImageView({
    image:'appImage/citytouchlogo.png',
    top:250,
    left:'150',
    height:100,
    widht:250
});
Ti.UI.currentWindow.add(txtLogoImage);
Ti.UI.currentWindow.add(loginButton);
Ti.UI.currentWindow.add(atmLocatorButton);
Ti.UI.currentWindow.add(branchLocatorButton);
Ti.UI.currentWindow.add(cityTouchLogoImage);

当有人点击登录按钮时,我想移动win2(Tab2)。我该怎么做?

如果要

从任何位置切换选项卡,请将其添加到定义选项卡组的位置,在本例中为应用.js:

Ti.App.addEventListener('app:gotoTab', function(e) {
    tabGroup.setActiveTab(e.tab);
});

将此添加到您的登录事件侦听器:

// tab index starts with 0, so 0 is your first tab
Ti.App.fireEvent('app:gotoTab', { tab: 1 });