离子2平台高度和宽度与方向变化不一致

时间:2017-11-17 09:56:32

标签: ionic-framework ionic2 ionic3

我正在尝试获取platform对象的屏幕高度和宽度,但显然屏幕方向会混淆这些值。

测试代码:

platform.ready().then(() => {
      console.log("orientation", screenOrientation.type);
      console.log("platform height", this.platform.height());
      console.log("platform width", this.platform.width());

      events.subscribe('orientation-changed', (screenOrientation) => {
        console.log("orientation", screenOrientation.type);
        console.log("platform height", this.platform.height());
        console.log("platform width", this.platform.width());
      });
    });

我以纵向模式开始运行应用程序,我得到:

orientation portrait-primary
platform height 567
platform width 360

我将手机旋转到横向,我得到:

orientation landscape-primary
platform height 567
platform width 360

直到现在,一切似乎都井然有序。 但现在,如果我将手机恢复为纵向模式,我会:

orientation portrait-primary
platform height 335
platform width 598

如果我再次转向横向:

orientation landscape-primary
platform height 567
platform width 360

如何在不关心手机方向的情况下获得正确的高度和宽度?

0 个答案:

没有答案