Puedo establecer la orientación en modo vertical únicamente en config.xml de la siguiente manera:
<preference name="Orientation" value="portrait"/>Pero, ¿cómo puedo permitir la orientación horizontal para las compilaciones de iPad, mientras sigo deshabilitando para iPhone como se indicó anteriormente?
Según Mike Harrison de Ionic, dice:
Aparte de rotar manualmente el dispositivo, en realidad no. Esto sería algo para lo que escribiría un complemento para modificar la vista principal de la aplicación en cordova
Pero hay un complemento de Ionic 1 . Míralo. Eventualmente, también puedes usarlo en Ionic 2.
Con este complemento podrías hacer algo como:
if(/(ipad)/i.test(navigator.userAgent)) { //THIS IS THE PLUGIN IONIC 1 CODE $scope.changeOriantationPortrait = function() { screen.lockOrientation('portrait'); } }Puede eliminar una preferencia de config.xml y definirla a través de un complemento nativo Orientación de pantalla
Luego, en app.component.ts bloqueo de orientación para teléfonos:
// check if platform is not a tablet if (platform.is('cordova') && !platform.is('tablet')) { // lock orientation to only portrait mode this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); // set screen orientation to 'portrait' globalProvier.screenOrientation = this.screenOrientation.ORIENTATIONS.PORTRAIT; } else { // if it's tablet // set device type to 'tablet' globalProvier.deviceType = platform.platforms()[3]; // set current orientation type ('portrait-primary' or 'landscape-primary' or 'portrait-secondary' or landscape-secondary) globalProvier.screenOrientation = this.screenOrientation.type; // set listener on changing orientation this.screenOrientation.onChange().subscribe( () => { globalProvier.screenOrientation = this.screenOrientation.type; console.log("Orientation Changed to: ", this.screenOrientation.type); } ); } Ahora puede ajustar dinámicamente su diseño dependiendo de las orientaciones de la tableta con la variable globalProvier.screenOrientation . Agregue clases o use *ngIf en las plantillas.
*ngIf='this.globalProvider.screenOrientation == "landscape-primary" || <h3 *ngIf='this.globalProvider.screenOrientation == "landscape-primary" || this.globalProvider.screenOrientation == "landscape-secondary"'>Orientation: landscape</h3>