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