メインコンテンツにスキップ
プラグインに戻る
@capgo/capacitor-screen-orientation
チュートリアル
github.com/Cap-go による

画面向き

画面向きプラグインは、画面ロックを回避するためのサポートを提供します。

ガイド

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

Using @capgo/capacitor-screen-orientation

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

インストール

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

このプラグインが提供するもの

  • orientation - 現在の画面の向きを取得する
  • lock - 画面の向きを特定のタイプに固定する
  • unlock - 画面の向きを解除する
  • startOrientationTracking - __CAPGO_KEEP_0__ を使用したデバイスの向きを追跡する

Example Usage

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

Motion Sensor を使用したデバイスの向きを追跡する

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

Full Reference