Reputation: 11198
I found this thread that will lock it for every device How to restrict app to portrait mode only in ionic for all platforms? but what I am looking to do is allow screen rotation on tablets, but not phones.
I was hoping this would be something I could setup in the config.xml, but I am thinking I am going to need something more like this https://ionicframework.com/docs/native/screen-orientation/ and do it programmatically unless I am missing something. Any ideas?
Upvotes: 0
Views: 986
Reputation: 905
You can use import { Platform} from 'ionic-angular';
for check device and import { ScreenOrientation } from '@ionic-native/screen-orientation';
for rotate your screen.
constructor(private navCtrl: NavController, private plt: Platform, private screen: ScreenOrientation) {
if (this.plt.is('tablet')) {
if (this.screen.type === 'portrait-primary') {
this.screen.lock(this.screen.ORIENTATIONS.LANDSCAPE);
}
}
}
This code with check if device is tablet and check if screen is portrait then it will automatically rotate your screen to landscape mode.
Upvotes: 2