ionic2/3 禁止屏幕旋轉,禁止橫屏,豎屏

ionic2/ionic3禁止屏幕旋轉,及解除禁止旋轉

1.添加插件:javascript

cmd到項目目錄--->html

cordova plugin add cordova-plugin-screen-orientation

  詳情看https://github.com/apache/cordova-plugin-screen-orientationjava

 

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();
    });
  }
}

  總結:git

這幾個方法組合使用能夠作:遊戲界面旋轉,視頻的旋轉與鎖定github

相關文章
相關標籤/搜索