在您希望標準方向的視圖中,添加一個自定義值,如doLandscape: 1
。我喜歡在app.config.Runtime類中設置運行時的「全局」值,否則如果它適用於整個應用程序,我會將它附加到導航欄。
Ext.define(‘MyApp.config.Runtime’,{
singleton : true,
config : {
doLandscape: 0 // initialize to 0
},
constructor : function(config){
this.initConfig(config);
}
});
在視口中,添加:
onOrientationChange: function(viewport, orientation, width, height) {
// test trigger and values
console.log('o:' + orientation + ' w:' + width + ' h:' + height);
if (orientation == 'landscape' && MyApp.config.Runtime.doLandscape === 0) {
// most often this is all that's needed to prevent change
return false;
// alternatively/additionally set it back to portrait manually.
viewport.orientation = this.PORTRAIT;
}
}
在更新的源代碼看,這裏是負責處理和火災方位的變化視口默認代碼。
onOrientationChange: function() {
var currentOrientation = this.getOrientation(),
newOrientation = this.determineOrientation();
if (newOrientation !== currentOrientation) {
this.fireOrientationChangeEvent(newOrientation, currentOrientation);
}
},
fireOrientationChangeEvent: function(newOrientation, oldOrientation) {
var clsPrefix = Ext.baseCSSPrefix;
Ext.getBody().replaceCls(clsPrefix + oldOrientation, clsPrefix + newOrientation);
this.orientation = newOrientation;
this.updateSize();
this.fireEvent('orientationchange', this, newOrientation, this.windowWidth, this.windowHeight);
}
當你在本地包裝,此選項可以作爲另一種選擇:
Ext.device.Orientation.on({
scope: this,
orientationchange: function(e) {
console.log('Alpha: ', e.alpha);
console.log('Beta: ', e.beta);
console.log('Gamma: ', e.gamma);
}
});