写在了launch方法 以便程序第一次加载就可以执行判断
Ext.define('Whaty.controller.Launch', {
extend: 'Ext.app.Controller',
config:{
refs:{
mainPanel:'MainPanel',
htmlPanel:'panel[itemId=htmlPanel]'
},
control:{
}
},
launch: function (){
// Initialize the main view
//要先加载viewport ,这样才能注册视图里面的控件
Ext.Viewport.add(Ext.create('Whaty.view.Main'));
var height = Ext.Viewport.getWindowHeight();
var width = Ext.Viewport.getWindowWidth();
this.handPortraitAndLandscape(width, height);
//orientationchange 这个在ST2 API里面能查到,系统会判断当前设备是否支持横竖屏判断,如果支持横竖屏切换时会触发handleOrientationChange
Ext.Viewport.on('orientationchange', 'handleOrientationChange', this);
},
handleOrientationChange: function() {
var height = Ext.Viewport.getWindowHeight();
var width = Ext.Viewport.getWindowWidth();
this.handPortraitAndLandscape(width, height);
},
handPortraitAndLandscape : function (width, height) {
if (width<height) {
alert("竖屏");
}
else {
alert("横屏");
}
}
});