码迷,mamicode.com
首页 > 其他好文 > 详细

ionic2/3 禁止屏幕旋转,禁止横屏,竖屏

时间:2017-05-23 16:59:16      阅读:1206      评论:0      收藏:0      [点我收藏+]

标签:any   项目目录   cto   logs   ble   ide   target   second   html   

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

  总结:

这几个方法组合使用可以做:游戏界面旋转,视频的旋转与锁定

ionic2/3 禁止屏幕旋转,禁止横屏,竖屏

标签:any   项目目录   cto   logs   ble   ide   target   second   html   

原文地址:http://www.cnblogs.com/babuge/p/6894797.html

(1)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!