メニューに進む

Getting Started

GitHub

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.

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

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

__CAPGO_KEEP_0__

__CAPGO_KEEP_1__

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

__CAPGO_KEEP_4__

__CAPGO_KEEP_5__

__CAPGO_KEEP_6__

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_9__

__CAPGO_KEEP_10__

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

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

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

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

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

motion-basedの向き追跡が開始されていた場合にのみ、モーションベースの向き追跡を停止します。

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

このメソッドは、物理的なデバイスの向き(モーションセンサ)とUIの向きを比較します。 UIの向きと物理的なデバイスの向きが異なる場合、向きロックは有効です。 Note: このメソッドは、startOrientationTracking()またはlock()でbypassOrientationLock: trueを指定した場合にのみ動作します。 iOS (Core Motion)とAndroid (Accelerometer)両方で動作します。

クリップボードにコピー

__CAPGO_KEEP_0__

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

__CAPGO_KEEP_1__

__CAPGO_KEEP_2__

ScreenOrientationResult

__CAPGO_KEEP_3__

__CAPGO_KEEP_4__

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

OrientationLockOptions

__CAPGO_KEEP_5__

__CAPGO_KEEP_6__

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

__CAPGO_KEEP_8__

__CAPGO_KEEP_0__

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. upstream の API が変更されたときに、再度 sync を実行してください。

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

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

あなたが「Getting Started」を使用している場合 Getting Started native メディアとインターフェイスの動作を計画するには、 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/capacitor-ビデオプレーヤー @capgo/capacitor-ビデオプレーヤーを使用して、ネイティブ機能を使用します。 @capgo/capacitor-ビデオプレーヤー @capgo/capacitor-ビデオプレーヤーの実装詳細を使用します。