ionic2/3 禁止屏幕旋转,禁止横屏,竖屏

1.添加插件:

cmd到项目目录--->

cordova plugin add cordova-plugin-screen-orientation

 

import { Component } from ‘@angular/core‘;
import { Platform } from ‘ionic-angular‘;
import { StatusBar } from ‘@ionic-native/status-bar‘;
import { SplashScreen } from ‘@ionic-native/splash-screen‘;
declare var screen :any;     //定义全局变量
@Component({
  templateUrl: ‘app.html‘
})
export class MyApp {
  rootPage:any = TabsPage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
      screen.orientation.lock(‘portrait-primary‘);
//     //锁定到主竖屏
//     screen.orientation.lock(‘portrait-primary‘);
//     //  //只禁止横屏
//      screen.orientation.lock(‘landscape‘);
//     //  //只禁止竖屏
//      screen.orientation.lock(‘portrait‘);
//     // //锁定到副竖屏
//     // screen.orientation.lock(‘portrait-secondary‘);
//     // //锁定到主横屏
//     // screen.orientation.lock(‘landscape-primary‘);
//     // //锁定到副横屏
//     // screen.orientation.lock(‘landscape-secondary‘);
//     // //解除屏幕锁定
//     // screen.orientation.unlock();
    });
  }
}

猜你喜欢

转载自blog.csdn.net/lc_style/article/details/78401841