Zum Hauptinhalt springen
Zurück zu Plugins
@capgo/capacitor-Bildschirmorientierung
Tutorial
von github.com/Cap-go

Bildschirmorientierung

Bildschirmorientierung-Plugin mit Unterstützung für das Umgehen des Orientierungssperre

Richtlinie

Tutorial zur Bildschirmorientierung

Mit @capgo/capacitor-screen-orientation

Capacitor-Bildschirmorientierung-Plugin-Schnittstelle

Installieren

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

Was dieses Plugin enthält

  • orientation - Aktuelle Bildschirmorientierung abrufen.
  • lock - Die Bildschirmorientierung auf eine bestimmte Art festlegen.
  • unlock - Die Bildschirmorientierung freigeben.
  • startOrientationTracking - Mit dem Gerätesensor die Geräteorientierung verfolgen.

Beispielhafte Verwendung

orientation

Ermitteln Sie die aktuelle Bildschirmorientierung.

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

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

lock

Die Bildschirmorientierung auf eine bestimmte Art sperren.

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

Die Bildschirmorientierung freigeben.

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

await ScreenOrientation.unlock();

startOrientationTracking

Mit dem Gerätesensor die Geräteorientierung verfolgen.

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

Vollständige Referenz