当我在纵向和横向两个方向上旋转屏幕时,ionic 2的android应用程序没有旋转
config.xml
<preference name='orientation' value='portrait'/>app.component.js
import { ScreenOrientation } from '@ionic-native/screen-orientation';
initializeApp() {
this.platform.ready().then(() => {
if (this.platform.isPortrait) { this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE); } else { this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); }
this.statusBar.styleDefault();
this.initPushNotification();
});
}发布于 2017-06-28 14:43:12
我找到了这个问题的答案,当手机屏幕方向改变时,应用程序也会随着手机方向旋转。
首先,从confix.xml中删除方向首选项
然后用app.component.js编写以下代码
app.component.js
if (this.platform.is('android')) {
this.ScreenOrientation.onChange().subscribe(() => {
if (this.platform.isPortrait) {
this.ScreenOrientation.unlock()
}
else {
this.ScreenOrientation.lock(this.ScreenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY)
}
});
}发布于 2017-06-28 16:20:41
首先安装..
ionic cordova插件添加cordova- plugin -screen-orientation
npm install --save @ionic native/screen-orientation
app.component.ts
import { ScreenOrientation } from '@ionic-native/screen-orientation';
constructor(private screenOrientation: ScreenOrientation) { }
// set to landscape
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
// allow user rotate
this.screenOrientation.unlock();
or
constructor(private screenOrientation: ScreenOrientation) {
this.screenOrientation.lock('portrait');
}https://stackoverflow.com/questions/44794311
复制相似问题