2014-07-21 105 views
0

我已成功實施this滑動導航庫。Sencha Touch 2按鈕啓用滑動導航

我可以將主視口滑入和滑出來顯示和隱藏視口左側的導航。

但是,我有點新手,無法找到隱藏和顯示通過按鈕點擊導航的方式。我會很感激任何方向來幫助我將現有的幻燈片導航配合到按鈕點擊操作中。

UPDATE:

我嘗試定製欄添加到Main.js是在一個名爲CustomBar類擴展標題欄的問題。然後我通過Main.js中的xtype使用它。下面的代碼顯示了我Main.js代碼與幻燈片導航庫配置:

Ext.define('RT.view.Main', { 
    extend: 'Ext.ux.slidenavigation.View', 
    xtype: 'main', 

    requires: [ 
     'Ext.TitleBar', 
     // 'Ext.Video' 
    ], 

    config: { 

     fullscreen: true, 
     // slideSelector: 'x-toolbar', 
     slideSelector: '', 
     containerSlideDelay: 10, 
     selectSlideDuration: 200, 
     itemMask: true, 
     /*slideButtonDefaults: { 
      selector: 'toolbar' 
     },*/ 
     listPosition: 'left', 
     list: { 
      maxDrag: 300, 
      width: 200, 
      items: [ 
       { 
        xtype: 'toolbar', 
        docked: 'top', 
        ui: 'light', 
        title: { 
         title: 'Menu', 
         centered: false, 
         width: 200, 
         left: 0, 
        }, 
        items: [{ 
         docked: 'top', 
         xtype: 'searchfield', 
         placeHolder: 'search', 
         width: 180 
        }] 
       } 
      ] 
     }, 
     slideButton: true, 
     slideButton: { 
      selector: 'toolbar' 
     }, 

     defaults: { 
      style: 'background: red', 
      xtype: 'container', 
     }, 
/****************************************************/ 

     items: [ 
      { 
       title: 'Welcome', 
       iconCls: 'home', 

       styleHtmlContent: true, 
       scrollable: true, 

       items: { 
        docked: 'top', 
        xtype: 'custombar', 
       }, 

       html: [ 
        "You've just generated a new Sencha Touch 2 project. What you're looking at right now is the ", 
        "contents of <a target='_blank' href=\"app/view/Main.js\">app/view/Main.js</a> - edit that file ", 
        "and refresh to change what's rendered here." 
       ].join("") 
      }, 
      { 
       title: 'Messages', 
       xtype: 'messages', 
       iconCls: 'user', 
      }, 
      { 
       title: 'Sections', 
       xtype: 'sections' 
      }, 
      { 
       title: 'submenu#1', 
       html: 'submenu#1', 
       group: 'Group 2', 
      }, 
      { 
       title: 'submenu#2', 
       html: 'submenu#2' 
      }, 
      { 
       title: 'submenu#3', 
       html: 'submenu#3' 
      }, 
     ] 
    } 
}); 

我customBar.js代碼如下:

Ext.define('RT.view.CustomBar',{ 
     extend: 'Ext.TitleBar', 
     xtype: 'custombar', 

     config:{ 

      title: 'TESTING ...', 
      items: [ 
       { 
        // name: 'BTNslidenav', 
        iconMask: true, 
        iconCls: 'list', 
        ui: 'plain', 
       }, 
       { 
        iconMask: true, 
        // iconCls: 'user', 
        iconCls: 'star', 
        ui: 'plain', 
        align: 'right' 
       } 
      ] 

     }// config 
    }); 

這customBar代碼由瀏覽靜態。我的LIST組件使用不同的解決方案來獲取NavigationBar並向其添加組件,以生成與CustomBar類似的外觀條。

我需要在CustomBar.js的預先存在的LIST圖標按鈕與幻燈片導航功能之間建立連接,以便我可以拖動或單擊圖標來顯示/隱藏導航菜單。

更新#2

已經跟着你的方向在下面,在我previous的問題,我對把我LIST後退按鈕到同一個工具欄作爲我的自定義導航不再工作實施的解決方案的更新。下圖顯示了我的結果:

enter image description here

我已經成功地使用下面的代碼來檢測信息和部分列表視圖,讓導航欄,並把我的圖標進入酒吧。 我的想法是,然後使用列表圖標上的監聽器來顯示/隱藏菜單。然而,因爲沒有監聽器,只是在slideButton配置,我的代碼是多餘的:

Ext.define('RT.controller.BarGenerator', { 
    extend: 'Ext.app.Controller', 

    config: { 
     refs: { 
      messagesView: 'messages', 
      sectionsView: 'sections' 
     }, 
     control: { 
      'sections': { 
       initialize: 'generateBarSections' 
      }, 
      'messages': { 
       initialize: 'generateBarMessages' 
      }, 
     } 
    }, 

    //called when the Application is launched, remove if not needed 
    launch: function(app) { 

    }, 
    generateBarSections: function(list, record){ 
     console.log('LOADING ICONS AND CUSTOMIZING BAR!'); 
     navigationview = this.getSectionsView().getNavigationBar(); 
     navigationview.add(
      { 
       // name: 'BTNslidenav', 
       id: 'BTNslidenav', 
       iconMask: true, 
       iconCls: 'list', 
       ui: 'plain', 
      }, 
      { 
       id: 'BTNuser', 
       iconMask: true, 
       iconCls: 'user', 
       ui: 'plain', 
       align: 'right' 
      } 
     ); 
    }, 
    generateBarMessages: function(list, record){ 
     console.log('LOADING ICONS AND CUSTOMIZING BAR!'); 
     navigationview = this.getMessagesView().getNavigationBar(); 
     navigationview.add(
      { 
       slideButton: { 
        selector: "custombar" 
       }, 
       // name: 'BTNslidenav', 
       id: 'BTNslidenav', 
       iconMask: true, 
       iconCls: 'list', 
       ui: 'plain', 
      }, 
      { 
       id: 'BTNuser', 
       iconMask: true, 
       iconCls: 'user', 
       ui: 'plain', 
       align: 'right' 
      } 
     ); 
    } 
}); 

回答

0

的Ext.ux.slidenavigation.View帶有一個滑動按鈕的功能。 你只需要指定按鈕的位置。

您可以使用容器填充Ext.ux.slidenaviagtion.View的項目數組。這些容器有一個屬性slideButton,您可以在其中定義一個選擇器,該選擇器用於查找應插入按鈕的組件。

items : [ 
    { 
     xtype : 'container', 
     group : 'my first group', 
     slideButton : 
     { 
      selector : 'toolbar' 
     }, 
     items : 
     [ 
      { 
       xtype : 'toolbar', 
       itemId : 'start_toolbar', 
       title : 'first view', 
       docked : 'top' 
      }, 
      { 
       xtype : 'start' 
      } 
     ] 
    }, 
    { 
     xtype : 'container', 
     group : 'my first group', 
     slideButton : 
     { 
      selector : 'toolbar' 
     }, 
     items : 
     [ 
      { 
       xtype : 'toolbar', 
       title : 'second view', 
       docked : 'top' 
      }, 
      { 
       xtype : 'anotherview' 
      } 
     ] 
    } 
] 

在該示例中Ext.ux.slidenavigation.View的項目數組2升的容器。一個容器總是容納兩個組件。一個工具欄和我想要展示的實際視圖。 slideButton config屬性定義該按鈕被插入到具有xtype工具欄的組件中。

更新:

感謝你們提供了一些代碼。我重新安排了你的代碼,所以它適合我的例子。

Ext.define('RT.view.CustomBar',{ 
     extend: 'Ext.TitleBar', 
     xtype: 'custombar', 

     config:{ 

      title: 'TESTING ...', 
      items: [ 
       { 
        iconMask: true, 
        // iconCls: 'user', 
        iconCls: 'star', 
        ui: 'plain', 
        align: 'right' 
       } 
      ] 

     }// config 
    }); 

首先,我已將您的按鈕從您的自定義欄中刪除。幻燈片導航將爲您創建按鈕。

Ext.define('RT.view.Main', { 
    extend: 'Ext.ux.slidenavigation.View', 
    xtype: 'main', 

    requires: [ 
     'Ext.TitleBar' 
    ], 

    config: { 
     fullscreen: true, 
     containerSlideDelay: 10, 
     selectSlideDuration: 200, 
     itemMask: true, 
     listPosition: 'left', 
     list: { 
      maxDrag: 300, 
      width: 200, 
      items: [ 
       { 
        xtype: 'toolbar', 
        docked: 'top', 
        ui: 'light', 
        title: { 
         title: 'Menu', 
         centered: false, 
         width: 200, 
         left: 0, 
        }, 
        items: [{ 
         docked: 'top', 
         xtype: 'searchfield', 
         placeHolder: 'search', 
         width: 180 
        }] 
       } 
      ] 
     }, 
     slideButton: true, 


/****************************************************/ 
     slideButtonDefaults: { 
      iconMask: true, 
      iconCls: 'list', 
      ui: 'plain' 
     }, 
     items: [ 
      { 
       xtype: "container", 
       group: "first group", 
       title: 'Welcome', 
       iconCls: 'home', 
       slideButton: { 
        selector:"custombar" 
       }, 
       items: [ 
        { 
          docked: 'top', 
          xtype: 'custombar', 
        }, 
        { 
         styleHtmlContent: true, 
         scrollable: true, 
         html: [ 
          "You've just generated a new Sencha Touch 2 project. What you're looking at right now is the ", 
          "contents of <a target='_blank' href=\"app/view/Main.js\">app/view/Main.js</a> - edit that file ", 
          "and refresh to change what's rendered here." 
         ].join("") 
        } 
       ] 
      }, 
      { 
       xtype: "container", 
       group: "first group", 
       title: 'Messages', 
       iconCls: 'user', 
       slideButton: { 
        selector: "custombar" 
       }, 
       items: [ 
        { 
          docked: 'top', 
          xtype: 'custombar', 
        }, 
         { 
         xtype: 'messages' 
         } 
       ] 
      } 
     ] 
    } 
}); 

由於滑動導航會爲你創建的滑鈕,就可以使用slideButtonDefaults來定製它。

滑動導航的items數組是重要的部分。 它現在包含兩個容器。這意味着你在側面導航中獲得兩個條目。這些容器中的每一個都包含您的自定義欄和您在側面導航中點擊某個條目時實際想要顯示的視圖。

每個包裝容器都定義了滑動按鈕將放置在其子視圖中的位置。這是由

slideButton: { 
    selector: 'custombar' 
} 

而就是這樣。

更新#2

這是因爲你現在有多個工具欄。測試工具欄被插入到將通過幻燈片導航顯示的每個容器中。另一個工具欄來自位於幻燈片導航容器內的導航視圖。

這是一些「修復」它的方法。

首先,您可以隱藏導航視圖工具欄,當它處於活動狀態並顯示導航視圖中的第一個視圖時。這個觀點是一個永遠不會有邏輯前驅的觀點,這一點很重要。因此,永遠不會有任何理由在該級別擁有後退按鈕。當您在導航視圖中開始導航並將更多視圖推送到它時,您可以隱藏「測試」工具欄。問題是:在每個子視圖中都有幻燈片按鈕很重要,還是僅在頂視圖上纔有它。考慮一下:工具欄中的許多按鈕相當多,可能會混淆用戶。打開滑動導航仍然可以通過滑動。

或者您完全不使用自定義欄,而是自定義導航視圖的標題欄。幻燈片導航的項目數組是這樣的:

items: [ 
      { 
       xtype: "container", 
       group: "first group", 
       title: 'Welcome', 
       iconCls: 'home', 
       slideButton: { 
        selector:"titlebar" 
       }, 
       items: [ 
        { 
         xtype: "navview" 
        } 
       ] 
      }, 
      { 
       xtype: "container", 
       group: "first group", 
       title: 'Messages', 
       iconCls: 'user', 
       slideButton: { 
        selector: "tilebar" 
       }, 
       items: [ 
        { 
         xtype: 'navView2' 
        } 
       ] 
      } 
     ] 

但要注意其在導航標題欄(停靠到左)兩個按鈕,當你開始推動的觀點。

+0

再次感謝你馬丁。我會盡快研究這個 – sisko

+0

嗨馬丁。請原諒我的無知,但我不明白您的示例代碼將如何幫助解決我的問題。所以,我用代碼更新了我的問題,這應該有助於更好地解釋一些事情 - 如果你能讓我更多地享受你的時間。 – sisko

+0

馬丁,非常感謝。我檢查了你對我的代碼的調整,這一切都很有意義,我將我的部分視圖添加到Main.js.然而,你之前的一個問題讓我重新浮出水面。我指的是LIST項目詳細信息視圖中的雙重工具欄。我在更新#2中添加了信息 – sisko