1. 程式人生 > >ionic2/3 禁止屏幕旋轉,禁止橫屏,豎屏

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

ide hide truct apach evel conda 定義 level 豎屏

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

1.添加插件:

cmd到項目目錄--->

cordova plugin add cordova-plugin-screen-orientation

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

import { Component } from [email protected]/core‘;
import { Platform } from ‘ionic-angular‘;
import { StatusBar } from [email protected]
/* *//status-bar‘; import { SplashScreen } from [email protected]/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(); }); } }

  總結:

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

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