Screen Orientation
Cordova plugin to set/lock the screen orientation in a common way.
Requires Cordova plugin: cordova-plugin-screen-orientation. For more info, please see the Screen Orientation plugin docs.
https://github.com/apache/cordova-plugin-screen-orientation
Stuck on a Cordova issue?
If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.
Installation#
- Capacitor
- Cordova
- Enterprise
$ npm install cordova-plugin-screen-orientation $ npm install @ionic-native/screen-orientation $ ionic cap sync$ ionic cordova plugin add cordova-plugin-screen-orientation $ npm install @ionic-native/screen-orientation Ionic Enterprise comes with fully supported and maintained plugins from the Ionic Team. Learn More or if you're interested in an enterprise version of this plugin Contact Us
Supported Platforms#
- Android
- iOS
- Windows
Usage#
React#
Learn more about using Ionic Native components in React
Angular#
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
constructor(private screenOrientation: ScreenOrientation) { }
...
// get currentconsole.log(this.screenOrientation.type); // logs the current orientation, example: 'landscape'
// set to landscapethis.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
// allow user rotatethis.screenOrientation.unlock();
// detect orientation changesthis.screenOrientation.onChange().subscribe( () => { console.log("Orientation Changed"); });