コンテンツにジャンプ

Getting Started

GitHub

CapgoのAIアシストセットアップを使用してプラグインをインストールできます。次のコマンドを使用して、CapgoスキルをAIツールに追加してください。

ターミナルウィンドウ
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.

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

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

APIの概要

APIの概要

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

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

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

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

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 がアップストリームで変更された場合に再度 Sync を実行してください。

Getting Started から続けてください

「Getting Started から続けてください」

Capacitor を使用している場合 Getting Started ネイティブメディアとインターフェイスの動作を計画する場合、Capacitor を Using @capgo/capacitor-screen-orientation Using @capgo/capacitor-screen-orientation Using @capgo/capacitor-live-activities Using @capgo/capacitor-live-activities @capgo/capacitor-live-activities 実装詳細のための@capgo/capacitor-live-activities Capgoで@capgo/capacitor-video-playerを使用する Capgoで@capgo/capacitor-video-playerを使用する @capgo/capacitor-video-player 実装詳細のための@capgo/capacitor-video-player