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();
    });
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章