Getting Started
Kopieren Sie eine Einrichtungsanweisung mit den Installationsanweisungen und der vollständigen Markdown-Guideline für diesen 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 mit dem Titel "Installieren"Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie die Capgo-Fähigkeiten Ihrem AI-Tool mithilfe der folgenden Befehl hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsVerwenden Sie dann die folgende Anfrage:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-screen-orientation` plugin in my project.Wenn Sie die manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und folgen Sie den unten aufgeführten Plattform-spezifischen Anweisungen:
bun add @capgo/capacitor-screen-orientationbunx cap syncImportieren
Abschnitt mit dem Titel „Importieren“import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';API-Übersicht
Abschnitt mit dem Titel “API Übersicht”orientation
Abschnitt mit dem Titel “Orientierung”Rufen Sie die aktuelle Bildschirmorientierung ab.
Ruft die aktuelle Orientierung des Gerätscreens ab.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();console.log('Current orientation:', result.type);Blockieren Sie die Bildschirmorientierung auf eine bestimmte Art.
Blockiert die Bildschirmorientierung auf die angegebene Weise. Bei iOS wird, wenn bypassOrientationLock wahr ist, auch die physische Geräteorientierung mithilfe von Bewegungssensoren verfolgt.
Hinweis: Die Benutzeroberfläche respektiert den Orientierungssperreinstellung des Benutzers weiterhin. Die Bewegungsverfolgung ermöglicht es Ihnen, zu erkennen, wie das Gerät physisch gehalten wird, ebenbei, wenn die Benutzeroberfläche nicht rotiert.
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});Freigeben Sie die Bildschirmorientierung.
Erstellt es dem Bildschirm ermöglicht, frei nach der Geräteposition zu rotieren. Außerdem stoppt es jede Bewegungsorientierungserkennung, wenn sie aktiviert war.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();startOrientationTracking
Abschnitt mit dem Titel “startOrientationTracking”Startet die Orientierung des Geräts mithilfe von Bewegungssensoren.
Dieser Methoden ist nützlich, wenn Sie die physische Orientierung des Geräts unabhängig von der Bildschirmorientierung sperren möchten. Es verwendet Core Motion auf iOS, um Orientierungsä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”Stoppt die Orientierung des Geräts mithilfe von Bewegungssensoren.
Stoppt die Bewegungsorientierungserkennung, wenn sie aktiviert war.
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();isOrientationLocked
Abschnitt mit dem Titel “isOrientationLocked”Überprüft, ob die Geräteorientierungssperre derzeit aktiviert ist.
Diese Methode vergleicht die physische Geräteorientierung (aus Bewegungssensoren) mit der Benutzeroberflächenoientierung. Wenn sie sich unterscheiden, ist die Orientierungssperre aktiviert.
Hinweis: Dies erfordert die Aktivierung der Bewegungsverfolgung über startOrientationTracking() oder lock() mit bypassOrientationLock: true. Funktioniert auf beiden iOS (Core Motion) und Android (Accelerometer).
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);}Typenreferenz
Abschnitt mit dem Titel „Typenreferenz“ScreenOrientationResult
Ergibt durch die Methode orientation() zurück.Auf die Zwischenablage kopieren
export interface ScreenOrientationResult { /** * The current orientation type. * * @since 1.0.0 */ type: OrientationType;}OrientationLockOptions
Optionen für die Sperre der Bildschirmorientierung.Auf die Zwischenablage kopieren
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
Section titled “StartOrientationTrackingOptions”Einstellungen für die Startorientierung 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
Sektion mit Titel „Orientierungssperre-Status-Ergebnis“Ergebnis, das von der Methode isOrientationLocked() 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
Sektion mit Titel „Orientierungstyp“Beschreibt den Orientierungszustand des Geräts.
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';OrientationLockType
Sektion mit Titel „Orientierungssperre-Typ“Orientierungssperre-Typ, der zum Sperren der Geräteorientierung verwendet werden kann.
export type OrientationLockType = | 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';Diese Seite wurde aus dem Plugin generiert. src/definitions.tsWiederholen Sie die Synchronisierung, wenn sich die öffentliche API im Quellcode ändert.
Weiter geht es mit Getting Started
Abschnitt mit dem Titel “Weiter geht es mit Getting Started”Wenn Sie native Medien und Schnittstellenverhalten planen, verbinden Sie es mit Getting Started Verwenden Sie @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-screen-orientation für die native Fähigkeit in Verwenden Sie @capgo/capacitor-screen-orientation Verwenden Sie @capgo/capacitor-live-activities für die native Fähigkeit in Verwenden Sie @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-aktivitäten für die Implementierungsdetails in @capgo/capacitor-live-aktivitäten Mit @capgo/capacitor-video-player für die native Fähigkeit in Mit @capgo/capacitor-video-player und @capgo/capacitor-video-player für die Implementierungsdetails in @capgo/capacitor-video-player.