使用 Appcelerator 在 iOS 上的 TabGroup 中打开 Windows
Opening Windows within a TabGroup on iOS with Appcelerator
我正在重新访问使用 Classic(不是 Alloy)创建的旧应用程序,需要删除已弃用的 window:url 功能,但在这个新更新中我需要添加一些导航 windows 在 tabGroup 里面。
我知道我需要创建一个可以调用的全局变量,这样我就可以在正确的选项卡中打开新的 window。
谁能指出我正确的方向?
所以我真的有两个问题。
- 导入另一个 JS 文件(在 Classic 中)以替换 window URL 方法的最佳方法是什么?
和
- 我该如何设置全局设置(同样是在 Classic 中)以便我可以在我的 tabGroup 中打开和关闭 windows?
这是我在 tabs.js 中的选项卡设置(URL 与我在 window 中的其他 JS 文件)
// create tab group
var tabGroup = Ti.UI.createTabGroup({
tintColor: '#FFF',
barColor: '#ff5700',
tabsTintColor:'#333333',
navTintColor: '#FFF',
tabsBackgroundColor :'#ff5700'
});
// Assign windows & tabs
var win1 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'team.js', title:'Team', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab1 = Titanium.UI.createTab({ window:win1, icon:'images/team.png', title:'Team', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/team.png', activeIconIsMask:true, iconIsMask:false});
var win2 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'league.js', title:'League', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab2 = Titanium.UI.createTab({ window:win2, icon:'images/league.png', title:'League', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/league.png', activeIconIsMask:true, iconIsMask:false});
var win3 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'fixtures.js', title:'Fixtures', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab3 = Titanium.UI.createTab({ window:win3, icon:'images/fixtures.png', title:'Fixtures', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/fixtures.png', activeIconIsMask:true, iconIsMask:false});
var win4 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'players.js', title:'Players', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab4 = Titanium.UI.createTab({ window:win4, icon:'images/players.png', title:'Players', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/players.png', activeIconIsMask:true, iconIsMask:false});
var win5 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'more.js', title:'More', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab5 = Titanium.UI.createTab({ window:win5, icon:'images/more.png', title:'More', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/more.png', activeIconIsMask:true, iconIsMask:false});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.addTab(tab3);
tabGroup.addTab(tab4);
tabGroup.addTab(tab5);
tabGroup.open();
这是我想在我的一个选项卡中调用另一个 window 的方式。我已经从中删除了大量代码,因为您不需要查看所有代码!
var createWin = Titanium.UI.createWindow({
backgroundColor: 'blue',
title: 'Create League'
});
createButton.addEventListener('click', function(){
tabGroup.activeTab.open(createWin);
});
我需要以某种方式将 tabGroup.activeTab.open(createWin); 纳入范围!
如有任何帮助,我们将不胜感激!
西蒙
您可以使用 Ti.App.tabGroup
使其成为全局,然后 Ti.App.tabGroup.activeTab.open(createWin);
首先,您的 windows 可能作为 CommonJS 模块位于另一个文件中。
像这样:
//tabTeam.js file
function tabTeam(){
var win = Ti.UI.createWindow({
backgroundColor:'yellow'
});
//put the code of your window here as usually
//don't forget to return the window
return win;
}
module.exports = tabTeam;
然后,对于选项卡组,正如塞巴斯蒂安所说,您应该选择 Ti.App 全局属性,例如:
Ti.App.tabgroup = Ti.UI.createTabGroup({}
backgroundColor:'white'
);
并要求 window,这样做:
var teamWindow = require("tabTeam")();
并将其添加到选项卡组:
var tab1 = Ti.UI.createTab({
icon:'asdasd.png',
window:teamWindow
});
并使用 tabgroup.open() 打开选项卡组。
如果您在一个 window 中,并且想在同一个选项卡中打开另一个 window,使用炫酷的 iOS 导航动画,请执行:
btOpenWindow.addEventListener('click',function(){
var profileWindow = require("profile")(parameters);
Ti.App.tabgroup.activeTab.open(profileWindow);
});
就是这样!让我知道是否有效 =)
在 app.js
中创建全局变量
var tabGroupGlobal;
在您当前的 window 中创建选项卡组并将其分配给全局变量
var tabGroup = Ti.UI.createTabGroup({
tintColor: '#FFF',
barColor: '#ff5700',
tabsTintColor:'#333333',
navTintColor: '#FFF',
tabsBackgroundColor :'#ff5700'
});
tabGroupGlobal = tabGroup;
现在您可以在任何 window.
中使用 tabGroupGlobal
btOpenWindow.addEventListener('click',function(){
var newWindow = Ti.UI.createWindow({});
tabGroupGlobal.activeTab.open(newWindow);
});
我认为这可能对您有所帮助。如果有任何错误或建议请告诉我。
我正在重新访问使用 Classic(不是 Alloy)创建的旧应用程序,需要删除已弃用的 window:url 功能,但在这个新更新中我需要添加一些导航 windows 在 tabGroup 里面。
我知道我需要创建一个可以调用的全局变量,这样我就可以在正确的选项卡中打开新的 window。
谁能指出我正确的方向?
所以我真的有两个问题。
- 导入另一个 JS 文件(在 Classic 中)以替换 window URL 方法的最佳方法是什么?
和
- 我该如何设置全局设置(同样是在 Classic 中)以便我可以在我的 tabGroup 中打开和关闭 windows?
这是我在 tabs.js 中的选项卡设置(URL 与我在 window 中的其他 JS 文件)
// create tab group
var tabGroup = Ti.UI.createTabGroup({
tintColor: '#FFF',
barColor: '#ff5700',
tabsTintColor:'#333333',
navTintColor: '#FFF',
tabsBackgroundColor :'#ff5700'
});
// Assign windows & tabs
var win1 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'team.js', title:'Team', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab1 = Titanium.UI.createTab({ window:win1, icon:'images/team.png', title:'Team', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/team.png', activeIconIsMask:true, iconIsMask:false});
var win2 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'league.js', title:'League', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab2 = Titanium.UI.createTab({ window:win2, icon:'images/league.png', title:'League', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/league.png', activeIconIsMask:true, iconIsMask:false});
var win3 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'fixtures.js', title:'Fixtures', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab3 = Titanium.UI.createTab({ window:win3, icon:'images/fixtures.png', title:'Fixtures', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/fixtures.png', activeIconIsMask:true, iconIsMask:false});
var win4 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'players.js', title:'Players', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab4 = Titanium.UI.createTab({ window:win4, icon:'images/players.png', title:'Players', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/players.png', activeIconIsMask:true, iconIsMask:false});
var win5 = Titanium.UI.createWindow({ backgroundColor:'#fff', barColor:'#ff5700', url:'more.js', title:'More', navTintColor:'#FFF', titleAttributes:{color: '#FFF'}});
var tab5 = Titanium.UI.createTab({ window:win5, icon:'images/more.png', title:'More', titleColor:'#FFF', activeTitleColor:'#333', activeIcon:'images/more.png', activeIconIsMask:true, iconIsMask:false});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
tabGroup.addTab(tab3);
tabGroup.addTab(tab4);
tabGroup.addTab(tab5);
tabGroup.open();
这是我想在我的一个选项卡中调用另一个 window 的方式。我已经从中删除了大量代码,因为您不需要查看所有代码!
var createWin = Titanium.UI.createWindow({
backgroundColor: 'blue',
title: 'Create League'
});
createButton.addEventListener('click', function(){
tabGroup.activeTab.open(createWin);
});
我需要以某种方式将 tabGroup.activeTab.open(createWin); 纳入范围!
如有任何帮助,我们将不胜感激!
西蒙
您可以使用 Ti.App.tabGroup
使其成为全局,然后 Ti.App.tabGroup.activeTab.open(createWin);
首先,您的 windows 可能作为 CommonJS 模块位于另一个文件中。 像这样:
//tabTeam.js file
function tabTeam(){
var win = Ti.UI.createWindow({
backgroundColor:'yellow'
});
//put the code of your window here as usually
//don't forget to return the window
return win;
}
module.exports = tabTeam;
然后,对于选项卡组,正如塞巴斯蒂安所说,您应该选择 Ti.App 全局属性,例如:
Ti.App.tabgroup = Ti.UI.createTabGroup({}
backgroundColor:'white'
);
并要求 window,这样做:
var teamWindow = require("tabTeam")();
并将其添加到选项卡组:
var tab1 = Ti.UI.createTab({
icon:'asdasd.png',
window:teamWindow
});
并使用 tabgroup.open() 打开选项卡组。
如果您在一个 window 中,并且想在同一个选项卡中打开另一个 window,使用炫酷的 iOS 导航动画,请执行:
btOpenWindow.addEventListener('click',function(){
var profileWindow = require("profile")(parameters);
Ti.App.tabgroup.activeTab.open(profileWindow);
});
就是这样!让我知道是否有效 =)
在 app.js
中创建全局变量var tabGroupGlobal;
在您当前的 window 中创建选项卡组并将其分配给全局变量
var tabGroup = Ti.UI.createTabGroup({
tintColor: '#FFF',
barColor: '#ff5700',
tabsTintColor:'#333333',
navTintColor: '#FFF',
tabsBackgroundColor :'#ff5700'
});
tabGroupGlobal = tabGroup;
现在您可以在任何 window.
中使用 tabGroupGlobalbtOpenWindow.addEventListener('click',function(){
var newWindow = Ti.UI.createWindow({});
tabGroupGlobal.activeTab.open(newWindow);
});
我认为这可能对您有所帮助。如果有任何错误或建议请告诉我。