画面向き __CAPGO_KEEP_0__ リポジトリ
このプラグインのインストール手順とフルマークダウンガイドを含むセットアッププロンプトをコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-screen-orientation`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/screen-orientation/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」のセクション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-orientationbunx cap syncImport
「Import」セクションimport { ScreenOrientation } from '@capgo/capacitor-screen-orientation';API の概要
「API の概要」セクションorientation
「orientation」セクション現在の画面の向きを取得します。
デバイスの画面の現在の向きを返します。
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();console.log('Current orientation:', result.type);lock
「ロック」のセクション画面の向きを特定のタイプに固定します。
指定された向きで画面をロックします。 iOSの場合、bypassOrientationLockがtrueの場合、motion sensorsを使用して物理デバイスの向きを追跡します。 注意: UIはユーザーの向きロック設定を尊重します。 物理的なデバイスの向きを検出するには、motion trackingを使用します。UIが回転しない場合でも、デバイスがどのように物理的に保持されているかを検出できます。
クリップボードにコピー
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Standard lockawait ScreenOrientation.lock({ orientation: 'landscape' });
// Lock with motion tracking on iOSawait ScreenOrientation.lock({ orientation: 'portrait', bypassOrientationLock: true});unlock
画面の向きをアンロックします。デバイスの位置に応じて画面を自由に回転させます。 また、motion-based orientation trackingも停止します。 もし以前motion trackingが有効になっていた場合。
クリップボードにコピー
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();startOrientationTracking
startOrientationTrackingモーションセンサを使用してデバイスの向きを追跡します。
このメソッドは、画面の向きロックとは独立してデバイスの物理的な向きを追跡したい場合に便利です。 iOSではCore Motionを使用して向きの変化を検出します。
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.startOrientationTracking({ bypassOrientationLock: true});
// Listen for changesScreenOrientation.addListener('screenOrientationChange', (result) => { console.log('Orientation changed:', result.type);});stopOrientationTracking
stopOrientationTrackingモーションセンサを使用してデバイスの向きを追跡中の場合に停止します。
モーションセンサを使用してデバイスの向きを追跡していた場合に停止します。
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();isOrientationLocked
isOrientationLockedデバイスの向きロックが現在有効かどうかを確認します。
このメソッドは、物理的なデバイスの向き(モーションセンサ)とUIの向きを比較します。 向きが異なる場合、向きロックは有効です。 注意:このメソッドは、startOrientationTracking()またはlock()でbypassOrientationLock: trueを指定した場合にのみ有効です。 iOS (Core Motion) と Android (Accelerometer) で動作します。
Copy to clipboard
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
// Start motion tracking firstawait ScreenOrientation.startOrientationTracking({ bypassOrientationLock: true});
// Check lock statusconst status = await ScreenOrientation.isOrientationLocked();if (status.locked) { console.log('Orientation lock is ON'); console.log('Physical:', status.physicalOrientation); console.log('UI:', status.uiOrientation);}型の参照
「型の参照」のセクションScreenOrientationResult
「画面の向きの結果」のセクション画面の向きを取得するorientation()メソッドの戻り値
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;}OrientationLockStatusResult
Section titled “OrientationLockStatusResult”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;}OrientationType
Section titled “OrientationType”デバイスの向き状態を表すオリエンテーションタイプ
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';OrientationLockType
Section titled “OrientationLockType”デバイスの向きをロックするために使用できるオリエンテーションロックタイプ
export type OrientationLockType = | 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';Source Of Truth
Section titled “Source Of Truth”このページはプラグインのソースから生成されています src/definitions.ts. APIがアップストリームで変更された場合に、パブリックを再度同步してください。
Getting Startedから続けてください
Getting Startedから続けてくださいCapgoを使用している場合 Getting Started Capgoを使用してネイティブメディアとインターフェイスの動作を計画するには、Capgoを @capgo/capacitor-screen-orientation Capgoを使用してネイティブ機能の@capgo/capacitor-screen-orientationを使用する場合 @capgo/capacitor-live-activities Capgoを使用してネイティブ機能の@capgo/capacitor-live-activitiesを使用する場合 @capgo/capacitor-live-activities @capgo/capacitor-live-activitiesの実装詳細 @capgo/capacitor-ビデオプレーヤー @capgo/capacitor-ビデオプレーヤー用のネイティブ機能 @capgo/capacitor-ビデオプレーヤー @capgo/capacitor-ビデオプレーヤー用の実装詳細