Saltar al contenido principal
Volver a plugins
@capgo/capacitor-orientación-de-pantalla
Tutoriales
por github.com/Cap-go

Orientación de pantalla

Plugin de orientación de pantalla con soporte para saltar el bloqueo de orientación

Guía

Tutorial sobre Orientación de Pantalla

Usando @capgo/capacitor-orientación-de-pantalla

Interface del plugin de orientación de pantalla de Capacitor.

Instalar

bun add @capgo/capacitor-screen-orientation
bunx cap sync

¿Qué se expone con este plugin?

  • orientation - Obtener la orientación de pantalla actual.
  • lock - Bloquear la orientación de pantalla a un tipo específico.
  • unlock - Desbloquear la orientación de pantalla.
  • startOrientationTracking - Comience a rastrear la orientación del dispositivo utilizando sensores de movimiento.

Ejemplo de uso

orientation

Obtenga la orientación actual de la pantalla.

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';

const result = await ScreenOrientation.orientation();
console.log('Current orientation:', result.type);

lock

Bloquee la orientación de la pantalla a un tipo específico.

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';

// Standard lock
await ScreenOrientation.lock({ orientation: 'landscape' });

// Lock with motion tracking on iOS
await ScreenOrientation.lock({
  orientation: 'portrait',
  bypassOrientationLock: true
});

unlock

Desbloquee la orientación de la pantalla.

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';

await ScreenOrientation.unlock();

startOrientationTracking

Comience a rastrear la orientación del dispositivo utilizando sensores de movimiento.

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';

await ScreenOrientation.startOrientationTracking({
  bypassOrientationLock: true
});

// Listen for changes
ScreenOrientation.addListener('screenOrientationChange', (result) => {
  console.log('Orientation changed:', result.type);
});

Referencia completa