Inizia a utilizzare
Copia un prompt di configurazione con i passaggi di installazione e la guida markdown completa per questo plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-screen-orientation`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/screen-orientation/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installa
Sezione intitolata “Installa”bun add @capgo/capacitor-screen-orientationbunx cap syncImporta
Sezione intitolata “Importa”import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';API Panoramica
Sezione intitolata “API Panoramica”orientation
Sezione intitolata “orientamento”Ottieni l'orientamento attuale della schermata.
Restituisce l'orientamento attuale della schermata del dispositivo.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();console.log('Current orientation:', result.type);Blocca l'orientamento della schermata a un tipo specifico.
Blocca la schermata all'orientamento specificato. Su iOS, se bypassOrientationLock è true, inizierà anche a tracciare l'orientamento fisico del dispositivo utilizzando i sensori di movimento.
Nota: L'interfaccia utente rispetterà comunque la impostazione del blocco dell'orientamento del utente. Il tracciamento del movimento consente di rilevare come il dispositivo è fisicamente tenuto e anche quando l'interfaccia utente non ruota.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Standard lockawait ScreenOrientation.lock({ orientation: 'landscape' });
// Lock with motion tracking on iOSawait ScreenOrientation.lock({ orientation: 'portrait', bypassOrientationLock: true});Sblocca l'orientamento dello schermo.
Consente allo schermo di ruotare liberamente in base alla posizione del dispositivo. Inoltre, ferma qualsiasi tracciamento dell'orientamento basato sulla movimentazione se era abilitato.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();startOrientationTracking
Sezione intitolata “avviaTracciamentoOrientamento”Avvia il tracciamento dell'orientamento del dispositivo utilizzando i sensori di movimento.
Questo metodo è utile quando desideri tracciare l'orientamento fisico del dispositivo indipendentemente dal blocco dell'orientamento dello schermo. Utilizza Core Motion su iOS per rilevare i cambiamenti di orientamento.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.startOrientationTracking({ bypassOrientationLock: true});
// Listen for changesScreenOrientation.addListener('screenOrientationChange', (result) => { console.log('Orientation changed:', result.type);});stopOrientationTracking
Sezione intitolata “fermaTracciamentoOrientamento”Ferma il tracciamento dell'orientamento del dispositivo utilizzando i sensori di movimento.
Ferma il tracciamento dell'orientamento basato sulla movimentazione se era stato avviato.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();isOrientationLocked
Sezione intitolata “isOrientationLocked”Verifica se il blocco dell'orientamento del dispositivo è attualmente abilitato.
Questo metodo confronta l'orientamento fisico del dispositivo (dai sensori di movimento) con l'orientamento dell'interfaccia utente. Se differiscono, il blocco dell'orientamento è abilitato.
Nota: Ciò richiede la tracciatura del movimento essere attiva tramite startOrientationTracking() o lock() con bypassOrientationLock: true. Funziona su entrambi iOS (Core Motion) e Android (Accelerometro).
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Start motion tracking firstawait ScreenOrientation.startOrientationTracking({ bypassOrientationLock: true});
// Check lock statusconst status = await ScreenOrientation.isOrientationLocked();if (status.locked) { console.log('Orientation lock is ON'); console.log('Physical:', status.physicalOrientation); console.log('UI:', status.uiOrientation);}Riferimento di tipo
Sezione intitolata “Riferimento di tipo”ScreenOrientationResult
Sezione intitolata “ScreenOrientationResult”Risultato restituito dal metodo orientation().
export interface ScreenOrientationResult { /** * The current orientation type. * * @since 1.0.0 */ type: OrientationType;}OrientationLockOptions
Sezione intitolata “OrientationLockOptions”Opzioni per bloccare l'orientamento dello schermo.
export interface OrientationLockOptions { /** * The orientation type to lock to. * * @since 1.0.0 */ orientation: OrientationLockType;
/** * Whether to track physical device orientation using motion sensors. * When true, uses device motion sensors to detect the true physical * orientation of the device, even when the device orientation lock is enabled. * * **Important:** This does NOT bypass the UI orientation lock. * The screen will still respect the user's orientation lock setting. * This option only affects orientation detection/tracking - you'll receive * orientation change events based on how the device is physically held, * but the UI will not rotate if orientation lock is enabled. * * Supported on iOS (Core Motion) and Android (Accelerometer). * * @default false * @since 1.0.0 */ bypassOrientationLock?: boolean;}StartOrientationTrackingOptions
Sezione intitolata “StartOrientationTrackingOptions”Opzioni per l'avvio del tracciamento dell'orientamento utilizzando i sensori di movimento.
export interface StartOrientationTrackingOptions { /** * Whether to track physical device orientation using motion sensors. * When true, uses device motion sensors to detect the true physical * orientation of the device, even when the device orientation lock is enabled. * * **Important:** This does NOT bypass the UI orientation lock. * This only enables detection of the physical orientation. * * Supported on iOS (Core Motion) and Android (Accelerometer). * * @default false * @since 1.0.0 */ bypassOrientationLock?: boolean;}OrientationLockStatusResult
Sezione intitolata “OrientationLockStatusResult”Risultato restituito dal metodo isOrientationLocked().
export interface OrientationLockStatusResult { /** * Whether the device orientation lock is currently enabled. * * This is determined by comparing the physical device orientation * (from motion sensors) with the UI orientation. If they differ, * orientation lock is enabled. * * Available on iOS (Core Motion) and Android (Accelerometer) when motion tracking is active. * * @since 1.0.0 */ locked: boolean;
/** * The physical orientation of the device from motion sensors. * Available when motion tracking is active (iOS and Android). * * @since 1.0.0 */ physicalOrientation?: OrientationType;
/** * The current UI orientation reported by the system. * * @since 1.0.0 */ uiOrientation: OrientationType;}OrientationType
Sezione intitolata “OrientationType”Tipo di orientamento che descrive lo stato di orientamento del dispositivo.
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';OrientationLockType
Sezione intitolata “OrientationLockType”Tipo di blocco di orientamento che può essere utilizzato per bloccare l'orientamento del dispositivo.
export type OrientationLockType = | 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';Fonte di Verità
Sezione intitolata “Fonte di Verità”Questa pagina è generata dal plugin’s src/definitions.ts. Riavvia la sincronizzazione quando le informazioni pubbliche API cambiano in fase di sviluppo.
Continua da Inizia a utilizzare
Sezione intitolata “Continua da Inizia a utilizzare”Se stai utilizzando Inizia a utilizzare per pianificare il comportamento nativo dei media e dell'interfaccia, connettilo con Utilizza @capgo/capacitor-orientamento dello schermo per la capacità nativa in Utilizza @capgo/capacitor-orientamento dello schermo Usando @capgo/capacitor-attività-in-vivo per la capacità nativa in Usando @capgo/capacitor-attività-in-vivo, @capgo/capacitor-attività-in-vivo per il dettaglio di implementazione in @capgo/capacitor-attività-in-vivo, Usando @capgo/capacitor-lettore-di-video per la capacità nativa in Usando @capgo/capacitor-lettore-di-video, e @capgo/capacitor-lettore-di-video per il dettaglio di implementazione in @capgo/capacitor-lettore-di-video.