当前位置: 代码迷 >> JavaScript >> Ext JS 中方向改变时的对话框位置改变
  详细解决方案

Ext JS 中方向改变时的对话框位置改变

热度:29   发布时间:2023-06-07 15:25:25.0

我想在屏幕中央显示 Ext.Dialog,这是通过使用 showBy 方法实现的,如下所示。

dialog.showBy(view.lookupReference('btn'), 'c-c');

它工作正常。 但是,当我更改 android 设备对话框中的方向时,它的位置会发生变化,并且只有一半的对话框可见。

我尝试了以下步骤。

  1. 提供的配置居中:true
  2. 动态使用中心方法
  3. orientationchange 事件似乎在 Ext 6.7 中被删除
  4. dialog.showBy(Ext.getBody(), 'c-c');
  5. dialog.showBy(Ext.Viewport, 'c-c');

无法通过上述任何方式实现,任何实现此目标的提示。 我正在使用 Ext JS 6.7

我会从 ExtJS 6.6 给你建议,小心它可以从 6.7 更新。

不久前我遇到了同样的问题,我发现了这个事件: :

好的,它仅在视口上,但我没有找到任何其他解决方案。

其实我做这样的事情:

在我的主视图初始化函数结束时:

Ext.Viewport.on('orientationchange',  this.getController().OnOrientationChange, this.getController());

在我的主视图控制器上:

OnOrientationChange: function(viewport, orientation) {  
    viewport.mask();

    var actualWidth = window.innerWidth;
    var actualHeight = window.innerHeight;

    // Orientation check due to latence can fake orientation result
    if (orientation === "landscape") {
        if (actualWidth < actualHeight) {
            Ext.defer(this.OnOrientationChange, 100, this, [viewport, orientation]);
            return;
        }
    }
    else if (orientation === "portrait") {
        if (actualWidth > actualHeight) {
            Ext.defer(this.OnOrientationChange, 100, this, [viewport, orientation]);
            return;
        }
    }

    viewport.unmask();

    // Xtype liste of object would by notified
    var objXtypeList = ['dataview', 'carousel', 'signingarea'];

    for (var i = 0, max = objXtypeList.length; i < max; i++) {
        var objXtype = objXtypeList[i];
        var objList = viewport.query(objXtype);

        for (var j = 0, maxJ = objList.length; j < maxJ; j++) {
            var obj = objList[j];
            if (Ext.isFunction(obj.OnOrientationChange)) {
                Ext.defer(obj.OnOrientationChange, 50, obj, [orientation]);
            }
        }
    }
}

每个对象的控制器都必须做出反应:

OnOrientationChange: function(orientation) {
    // The way the object should react
}

我不知道这是否是最正确的方法,但它对我有用。

  相关解决方案