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


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

1.添加插件:

cmd到項目目錄--->

cordova plugin add cordova-plugin-screen-orientation

  詳情看https://github.com/apache/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();
    });
  }
}

  總結:

這幾個方法組合使用可以做:游戲界面旋轉,視頻的旋轉與鎖定


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM