2016-01-20 150 views
0

加载平板电脑视图时出现的问题。我正在维护手机和平板电脑的单独导航视图。但仍然在加载平板电脑时需要查看电话。如果我试图创建标准集装箱,我可以做到,但不与导航视图以sencha加载平板电脑视图

Tablet.js

Ext.define('ABCapp.profile.Tablet', { 
     extend: 'ABCapp.profile.Base', 

     config: { 
      name: 'Tablet', 
      views: [ 

       'ABCapp.view.tablet.HomeView', 
       'ABCapp.view.tablet.home.HomeViewMain', 
      ] 
     }, 

     isActive: function() { 
      return Ext.os.is.Tablet || Ext.os.is.Desktop; 
     }, 
     launch: function() { 
      console.log('Tablet Init'); 
      Ext.Viewport.add(Ext.create('ABCapp.view.tablet.HomeView')); 
      this.callParent(); 
     } 
    }); 

Phone.js

Ext.define('ABCapp.profile.Phone', { 
     extend: 'ABCapp.profile.Base', 

     config: { 
     name: 'Tablet', 
     views:[ 


      'ABCapp.view.tablet.HomeView', 
      'ABCapp.view.tablet.home.HomeViewMain', 


     ] 
     }, 

     isActive: function() { 
    return Ext.os.is.Phone; 
}, 

    launch: function() { 
     console.log('Phone Init'); 
     Ext.Viewport.add(Ext.create('ABCapp.view.phone.HomeView')); 
      this.callParent(); 
    } 
}); 

Homeview平板

Ext.define('ABCapp.view.tablet.HomeView', { 
     extend: 'Ext.navigation.View', 
     xtype: 'homeView', 

     config:{    
      id:'homeView', 
      navigationBar: { 
      hidden: true 
      }, 
      items: [ 
       { 
       xtype: 'homeViewMain' 
       } 
     ] 
     } 

});

+0

你应该仔细看看你的Phone.js'isActive'函数。如果Phone.js是平板电脑或桌面,则将其设置为活动状态。 – Alexander

+0

对不起亚历山大其错字错误 –

+0

isActive:function(){ return Ext.os.is.Phone; }, –

回答

1

我以前遇到同样的问题,我认为Ext.os.is.Phone不是检测设备的正确方法。例如,它正在将我的7inc android平板电脑作为手机进行检测。

因此,最好是为平板电话分离编写自己的算法。这是我以前用于小屏幕的:

isActive: function(){ 
    var width = Ext.getBody().getWidth(); 
    var height = Ext.getBody().getHeight(); 

    var pw = Math.min(width, height); // portrait width 
    var ph = Math.max(width, height); // portrait height 

    // assume 600-width and 750-height in portrait mode are bounds 
    var maxWidth = 620, 
     maxHeight = 750; 

    return (pw <= maxWidth && ph <= maxHeight); 

    // iphone6: 375*667 (portrait) 
    // ipadmini: 1024*768 
    // nexus7: 966*604 
    // lenovo7inc: 1024*527 (statusbars...) 
}