Saltare al contenuto

Iniziare

GitHub

Puoi utilizzare la nostra configurazione assistita da AI per installare il plugin. Aggiungi le Capgo competenze al tuo strumento AI utilizzando il seguente comando:

Finestra del terminale
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Poi utilizza la seguente richiesta:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-screen-orientation` plugin in my project.

Se preferisci la configurazione manuale, installa il plugin eseguendo i seguenti comandi e segui le istruzioni specifiche del tuo sistema operativo riportate di seguito:

Finestra del terminale
bun add @capgo/capacitor-screen-orientation
bunx cap sync
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';

Ottieni l'orientamento attuale dello schermo.

Restituisce l'orientamento attuale dello schermo del dispositivo.

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();
console.log('Current orientation:', result.type);

Blocca l'orientamento dello schermo a un tipo specifico.

Blocca lo schermo 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 di blocco dell'orientamento del utente. Il tracciamento di movimento consente di rilevare come il dispositivo è fisicamente tenuto anche quando l'interfaccia utente non si gira.

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
});

Sblocca l'orientamento dello schermo.

Consente alla schermata di ruotare liberamente in base alla posizione del dispositivo. Inoltre, ferma qualsiasi tracciamento dell'orientamento basato sulla movenza se era abilitato.

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();

Avvia il tracciamento dell'orientamento del dispositivo utilizzando i sensori di movenza.

Sottosezione intitolata “stopOrientationTracking”

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);
});

Copiare nel portapennelli

Sottosezione intitolata “isOrientationLocked”

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();

isOrientationLocked

Copy to clipboard

Sezione intitolata “startOrientationTracking”

Questo metodo confronta l'orientamento fisico del dispositivo (ottenuto dai sensori di movimento) con l'orientamento dell'interfaccia utente. Se differiscono, viene abilitata la bloccatura dell'orientamento.

Nota: Ciò richiede la tracciatura del movimento 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 first
await ScreenOrientation.startOrientationTracking({
bypassOrientationLock: true
});
// Check lock status
const status = await ScreenOrientation.isOrientationLocked();
if (status.locked) {
console.log('Orientation lock is ON');
console.log('Physical:', status.physicalOrientation);
console.log('UI:', status.uiOrientation);
}

Risultato restituito dal metodo orientation().

export interface ScreenOrientationResult {
/**
* The current orientation type.
*
* @since 1.0.0
*/
type: OrientationType;
}

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;
}

Opzioni per l'avvio della tracciatura 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;
}

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;
}

Tipo di orientamento che descrive lo stato di orientamento del dispositivo.

export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';

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';

Questa pagina è generata dal plugin’s src/definitions.tsRiepilogare la sincronizzazione quando le informazioni pubbliche API cambiano in fase di sviluppo.

Se stai utilizzando Iniziare per pianificare il comportamento dei media nativi e dell'interfaccia, connettilo con Utilizzando @capgo/capacitor-orientamento dello schermo per la capacità nativa in Utilizzando @capgo/capacitor-orientamento dello schermo, Utilizzando @capgo/capacitor-attività in diretta per la capacità nativa in Utilizzando @capgo/capacitor-attività in diretta, @capgo/capacitor-live-attivitàs per i dettagli di implementazione in @capgo/capacitor-live-attivitàs Utilizzo di @capgo/capacitor-player-video per la capacità nativa in Utilizzo di @capgo/capacitor-player-video, e @capgo/capacitor-player-video per i dettagli di implementazione in @capgo/capacitor-player-video.