[英]Ionic 2 Crosswalk for Android: this.platform.height()/width() inconsistent result on this.platform.ready() event
我在Ionic 2上使用了适用于Android的Crosswalk插件,并且注意到在实际设备上运行时,这会产生不一致的结果:
this.platform.ready().then(() => {
console.log("this.platform.height(): " + this.platform.height() + " / this.platform.width(): " + this.platform.width());
});
有时我的高度和宽度都> 0:在这种情况下,它可以工作。
有时我得到的高度和宽度== 0:在这种情况下,它不起作用。
我的假设是,Crosswalk中可能会发生另一个事件,通知它已准备好显示正确的高度和宽度。
我环顾了这个Crosswalk网络api页面,但没有找到想要的东西。
https://ionicframework.com/docs/v2/api/platform/Platform/
width()
Gets the width of the platform’s viewport using window.innerWidth. Using this method is preferred since the dimension is a cached value, which reduces the chance of multiple and expensive DOM reads.
height()
Gets the height of the platform’s viewport using window.innerHeight. Using this method is preferred since the dimension is a cached value, which reduces the chance of multiple and expensive DOM reads.
// Add readySource to check if platform ready was used. The resolved value is the readySource, which states which platform ready was used. // For example, when Cordova is ready, the resolved ready source is cordova. The default ready source value will be dom. import { Component } from '@angular/core'; import { Platform } from 'ionic-angular'; @Component({...}) export MyApp { constructor(platform: Platform) { platform.ready().then((readySource) => { console.log('Platform ready from', readySource); console.log('Width: ' + platform.width()); console.log('Height: ' + platform.height()); }); }
相关主题: https : //forum.ionicframework.com/t/how-to-get-device-width-and-height/28372
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.