Skip to content

Getting Started

GitHub

CapgoのAIアシストセットアップを使用してプラグインをインストールできます。次のコマンドを使用して、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.

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

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

APIの概要

APIの概要

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

__CAPGO_KEEP_0__の概要

デバイスの位置に応じて画面を自由に回転させることができます。 また、モーションに基づくオーリエンテーション追跡が有効になっていた場合に、その追跡を停止します。

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

タイプ リファレンス

タイプ リファレンス

ScreenOrientationResult

向きの結果

コピー

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

OrientationLockOptions

コピー

向きの追跡を開始するオプション

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

StartOrientationTrackingOptions

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

モーションセンサを使用したオーリエンテーション追跡の開始オプション。

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 がアップストリームで変更されたときは、再度同期を実行してください。

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

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

「Getting Started」を使用している場合 Getting Started ネイティブメディアとインターフェイスの動作を計画するには、 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 @capgo/capacitor-live-activitiesの実装詳細について Capgo @capgo/capacitor-video-playerを使用 Capgo @capgo/capacitor-video-playerのネイティブ機能を使用 @capgo/capacitor-video-player Capgo @capgo/capacitor-video-playerの実装詳細について