【问题标题】:Opening Windows within a TabGroup on iOS with Appcelerator使用 Appcelerator 在 iOS 上的 TabGroup 中打开窗口
【发布时间】:2016-01-20 14:03:47
【问题描述】:

我正在重新访问使用 Classic(不是 Alloy)创建的旧应用,需要删除已弃用的 window:url 功能,但在这次新更新中,我需要在 tabGroup 中添加一些导航窗口。

我知道我需要创建一个可以调用的全局变量,以便在正确的选项卡中打开新窗口。

谁能指出我正确的方向?

所以我真的有两个问题。

  1. 导入另一个 JS 文件(在 Classic 中)替换窗口 URL 方法的最佳方法是什么?

  1. 如何设置全局设置(再次在 Classic 中),以便可以在 tabGroup 中打开和关闭窗口?

这是我在 tabs.js 中的选项卡设置(带有指向窗口中其他 JS 文件的 URL)

    // 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();

这是我想在我的一个标签中的另一个窗口中调用的方式。我已经从中删减了大量代码,因为您不需要查看所有代码!

var createWin = Titanium.UI.createWindow({
    backgroundColor: 'blue',
    title: 'Create League'
});

createButton.addEventListener('click', function(){
    tabGroup.activeTab.open(createWin);
});

我需要以某种方式将 tabGroup.activeTab.open(createWin); 纳入范围!

任何帮助将不胜感激!

西蒙

【问题讨论】:

    标签: javascript ios titanium appcelerator


    【解决方案1】:

    您可以使用 Ti.App.tabGroupTi.App.tabGroup.activeTab.open(createWin); 使其全局化

    【讨论】:

      【解决方案2】:

      首先,您的窗口可以作为 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;
      

      那么,对于标签组,正如 Sebastian 所说,您应该选择 Ti.App 全局属性,例如:

      Ti.App.tabgroup = Ti.UI.createTabGroup({}
          backgroundColor:'white'
      );
      

      并要求窗口,这样做:

      var teamWindow = require("tabTeam")();
      

      并将其添加到选项卡组中:

      var tab1 = Ti.UI.createTab({
          icon:'asdasd.png',
          window:teamWindow
      });
      

      并使用 tabgroup.open() 打开标签组。

      如果您在一个窗口内,并且想在同一个标​​签页中打开另一个窗口,并使用酷炫的 iOS 导航动画,请执行以下操作:

      btOpenWindow.addEventListener('click',function(){
          var profileWindow = require("profile")(parameters);
          Ti.App.tabgroup.activeTab.open(profileWindow);
      });
      

      就是这样!让我知道是否有效 =)

      【讨论】:

      • 太棒了!我去试试,谢谢你的回答:)
      【解决方案3】:

      在 app.js 中创建全局变量

      var tabGroupGlobal;
      

      在您当前的窗口中创建标签组并将其分配给全局变量

      var tabGroup = Ti.UI.createTabGroup({
          tintColor: '#FFF',
          barColor: '#ff5700',
          tabsTintColor:'#333333',
          navTintColor: '#FFF',
          tabsBackgroundColor :'#ff5700'
      });
      
      tabGroupGlobal = tabGroup;
      

      现在您可以在任何窗口中使用 tabGroupGlobal。

      btOpenWindow.addEventListener('click',function(){
          var newWindow = Ti.UI.createWindow({});
          tabGroupGlobal.activeTab.open(newWindow);
      });
      

      我认为这可能会对您有所帮助。如果有任何错误或建议,请告诉我。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-11
        • 2012-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多