Erste Schritte
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses 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.
Installieren
Abschnitt „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze dann diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-screen-orientation` plugin in my project.Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
bun add @capgo/capacitor-screen-orientationbunx cap syncImportieren
Abschnitt mit dem Titel „Import“import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';Quickstart
Abschnitt „Quick start“import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();console.log('Current orientation:', result.type);Beispiel: lock
Abschnitt mit dem Titel „Beispiel: lock“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});Beispiel: unlock
Abschnitt mit dem Titel „Beispiel: unlock“import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();Häufige Stolperfallen
Abschnitt „Häufige Fallstricke“- Listener: Handles beim Unmounten von Screens entfernen.
- Nativer Sync: ausführen
bunx cap syncnach Plugin-Upgrades. - Single Source of Truth: Vertrauen
src/definitions.tsim GitHub Repo.
API Übersicht
Abschnitt „API Übersicht“orientation
Abschnitt mit dem Titel „orientation“Die aktuelle Bildschirmausrichtung abrufen.
Gibt die aktuelle Ausrichtung des Bildschirms zurück.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();console.log('Current orientation:', result.type);Die Bildschirmausrichtung auf einen bestimmten Typ fixieren.
Sperrt den Bildschirm auf die angegebene Ausrichtung. Auf iOS startet bei bypassOrientationLock = true zusätzlich das Tracking der physischen Geräteausrichtung über Bewegungssensoren.
Hinweis: Die UI respektiert weiterhin die Ausrichtungssperre des Nutzers. Motion Tracking erlaubt es zu erkennen, wie das Gerät physisch gehalten wird, auch wenn sich die UI nicht dreht.
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});Die Bildschirmausrichtung entsperren.
Ermöglicht dem Bildschirm, sich frei nach der Geräteposition zu drehen. Stoppt außerdem bewegungsbasiertes Motion Tracking, falls es aktiviert war.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();startOrientationTracking
Abschnitt mit dem Titel „startOrientationTracking“Tracking der Geräteausrichtung mit Bewegungssensoren starten.
Diese Methode ist nützlich, wenn du die physische Ausrichtung des Geräts unabhängig von der Sperrung der Bildschirmausrichtung verfolgen möchtest. Sie verwendet Core Motion auf iOS, um Ausrichtungsänderungen zu erkennen.
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
Abschnitt mit dem Titel „stopOrientationTracking“Tracking der Geräteausrichtung mit Bewegungssensoren stoppen.
Stoppt die bewegungsbasierte Ausrichtungsverfolgung, falls sie gestartet wurde.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();isOrientationLocked
Abschnitt mit dem Titel „isOrientationLocked“Prüfen, ob die Ausrichtungssperre aktuell aktiviert ist.
Diese Methode vergleicht die physische Geräteausrichtung (aus den Bewegungssensoren) mit der UI-Ausrichtung. Wenn sie sich unterscheiden, ist die Ausrichtung gesperrt.
Hinweis: Dies erfordert, dass die Bewegungserfassung über startOrientationTracking() oder lock() mit bypassOrientationLock: true aktiviert ist. Funktioniert sowohl auf iOS (Core Motion) als auch auf Android (Beschleunigungssensor).
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);}Typreferenz
Abschnitt mit dem Titel „Typreferenz“ScreenOrientationResult
Abschnitt mit dem Titel „ScreenOrientationResult“Ergebnis, das von der orientation()-Methode zurückgegeben wird.
export interface ScreenOrientationResult { /** * The current orientation type. * * @since 1.0.0 */ type: OrientationType;}OrientationLockOptions
Abschnitt mit dem Titel „OrientationLockOptions“Optionen zum Sperren der Bildschirmlausrichtung.
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
Abschnitt mit dem Titel „StartOrientationTrackingOptions“Optionen zum Starten der Ausrichtungserfassung mit Bewegungssensoren.
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
Abschnitt mit dem Titel „OrientationLockStatusResult“Ergebnis, das von der isOrientationLocked()-Methode zurückgegeben wird.
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
Abschnitt mit dem Titel „OrientationType“Orientierungstyp, der den Orientierungszustand des Geräts beschreibt.
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';OrientationLockType
Abschnitt mit dem Titel „OrientationLockType“Orientierungs-Sperrentyp, der zum Sperren der Geräteorientierung verwendet werden kann.
export type OrientationLockType = | 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.
Weiter geht's nach Getting Started
Abschnitt: „Weiter geht’s mit Getting Started“Wenn du es nutzt Erste Schritte , um natives Media- und Interface-Verhalten zu planen, verbinde es mit @capgo/capacitor-screen-orientation verwenden für die native Funktion in Using @capgo/capacitor-screen-orientation, @capgo/capacitor-live-activities verwenden für die native Funktion in „@capgo/capacitor-live-activities verwenden“, @capgo/capacitor-live-activities für die Implementierungsdetails in @capgo/capacitor-live-activities, Verwendung von @capgo/capacitor-video-player für die native Funktion in „@capgo/capacitor-video-player verwenden“, und @capgo/capacitor-video-player für das Implementierungsdetail in @capgo/capacitor-video-player.