メインコンテンツにジャンプ

ガイド

画面の向きに関するチュートリアル

デバイスでテスト

Download the Capgo app, then scan the QR code.

画面向きプラグインプレビューQR code

@capgo/capacitor-screen-orientationを使用します。

Capacitor画面向きプラグインインターフェイス

インストール

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

このプラグインが公開するもの

  • orientation - 現在の画面向きを取得します。
  • lock - 特定のタイプの画面向きをロックします。
  • unlock - 画面向きをアンロックします。
  • startOrientationTracking - モーションセンサーを使用してデバイスの向きを追跡します。

例の使用

orientation

現在の画面向きを取得します。

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

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

lock

画面の向きを特定のタイプに固定します。

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

画面の向きを解除します。

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

await ScreenOrientation.unlock();

startOrientationTracking

モーションセンサを使用してデバイスの向きを追跡します。

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

フルリファレンス

Keep going from Using @capgo/capacitor-screen-orientation

Capacitor Screen Orientation を使用している場合 Using @capgo/capacitor-screen-orientation Capacitor Screen Orientation を使用してネイティブのメディアとインターフェイスの動作を計画します。 @capgo/capacitor-screen-orientation @capgo/capacitorの実装詳細 Getting Started @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-live-activitiesの使用 @capgo/capacitor-live-activitiesのネイティブ機能 @capgo/capacitor-live-activities @capgo/capacitor-live-activitiesの実装詳細、そして @capgo/capacitor-video-playerの使用 @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-video-player.