ionic3 关于屏幕方向问题

关于屏幕方向问题

使用ionic-native中的screen-orientation

ionic cordova plugin add cordova-plugin-screen-orientation
npm install --save @ionic-native/screen-orientation
app.module.ts 的 providers 进行引用 ScreenOrientation。

在真机中才会看到效果,可以配合页面的生命周期进行设置,也可以在app.component.ts中全局设置

设置:

import { ScreenOrientation } from '@ionic-native/screen-orientation';
constructor(private screenOrientation: ScreenOrientation) { }


// get current
console.log(this.screenOrientation.type); // logs the current orientation, example: 'landscape'

// set to landscape
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);

// allow user rotate
this.screenOrientation.unlock();

// detect orientation changes
this.screenOrientation.onChange().subscribe(
  () => {
    console.log("Orientation Changed");
  }
);

举例:reportPage【报表页面,需要横屏显示,页面返回后取消锁定】

ionViewWillEnter(){
  this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
}
ionViewWillLeave(){
  this.screenOrientation.unlock();
}
ionViewDidLoad() {

}


锁定方向

portrait-primary Portrait模式, Home键在下边
portrait-secondary Portrait模式, Home键在上边
landscape-primary Landscape模式, Home键在右边
landscape-secondary Landscap模式, Home键在左边
portrait: 所有portrait模式
landscape: 所有landscape模式

官方详细内容
  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值