__CAPGO_KEEP_4__

Getting Started

GitHub

CapgoのAI-Assistedセットアップを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。

ターミナル画面
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のコマンドを実行してください。

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-screen-orientation` plugin in my project.

手動セットアップを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の手順に従ってください。

ターミナル画面
bun add @capgo/capacitor-screen-orientation
bunx cap sync
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';

現在の画面の向きを取得する

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

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();
console.log('Current orientation:', result.type);

画面の向きを特定のタイプに固定する

画面を指定された向きに固定します。 iOSでは、bypassOrientationLockがtrueの場合、物理的なデバイスの向きをモーションセンサで追跡します。

注意: UIはユーザーの向きのロック設定を尊重します。 モーション追跡により、UIが回転しない場合でも、デバイスが物理的にどのように保持されているかを検出できます。

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

画面の向きを解除する

画面をデバイスの位置に応じて自由に回転させることもできます。 また、モーションベースの向きの追跡も停止します。

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();

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

このメソッドは、画面の向きロックとは独立してデバイスの物理的な向きを追跡したい場合に便利です。 iOSではCore Motionを使用して向きの変化を検出します。

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

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

モーションベースの向きの追跡を停止します。

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();

デバイスの向きロックが現在有効かどうかを確認します。

このメソッドは、物理デバイスの向き(モーションセンサ)とUIの向きを比較します。 向きが異なる場合、向きロックは有効です。

注意: この機能は、startOrientationTracking() または lock() を使用して、bypassOrientationLock: true を有効にする必要があります。 iOS (Core Motion) と Android (Accelerometer) で動作します。

import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Start motion tracking first
await ScreenOrientation.startOrientationTracking({
bypassOrientationLock: true
});
// Check lock status
const status = await ScreenOrientation.isOrientationLocked();
if (status.locked) {
console.log('Orientation lock is ON');
console.log('Physical:', status.physicalOrientation);
console.log('UI:', status.uiOrientation);
}

画面向きの結果

export interface ScreenOrientationResult {
/**
* The current orientation type.
*
* @since 1.0.0
*/
type: OrientationType;
}

画面向きのロックのオプション

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

モーションセンサーの向きの追跡のオプション

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

isOrientationLocked() メソッドによって返される結果。

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

デバイスの向き状態を表すオリエンテーションタイプ。

export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';

デバイスの向きをロックするために使用できるオリエンテーションロックタイプ。

export type OrientationLockType =
| 'any'
| 'natural'
| 'landscape'
| 'portrait'
| 'portrait-primary'
| 'portrait-secondary'
| 'landscape-primary'
| 'landscape-secondary';

このページはプラグインから生成されます。 src/definitions.ts. 同期を再実行してください。 公開 API がアップストリームで変更されたとき。

Capacitorを使用している場合 Getting Started native media とインターフェイスの動作を計画するには、を接続する ネイティブ機能の@capgo/capacitor-screen-orientationの使用 ネイティブ機能の@capgo/capacitor-live-activitiesの使用 ネイティブ機能の@capgo/capacitor-live-activitiesの使用 @capgo/capacitor-live-activities @capgo/capacitor-ライブアクティビティ Capgoの実装詳細については@capgo/capacitor-live-activitiesを参照してください。 Capgoの@capgo/capacitor-video-playerを使用します。 Capgoのネイティブ機能については、Capgoの@capgo/capacitor-video-playerを使用します。 @capgo/capacitor-video-player @capgo/capacitor-video-playerの実装詳細のために。