在您希望标准方向的视图中,添加一个自定义值,如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);
}
});