画面の向き __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.
インストール
「インストール」のセクションbun add @capgo/capacitor-screen-orientationbunx 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);lock
「ロック」セクション__CAPGO_KEEP_0__を特定のタイプに固定します。
__CAPGO_KEEP_0__を指定された向きに固定します。 iOSの場合、bypassOrientationLockがtrueの場合、motion sensorsを使用して物理的なデバイスの向きを追跡します。 注意: UIはユーザーの向きロック設定を尊重します。 物理的なデバイスの向きを検出するには、UIが回転しない場合でもmotion trackingを使用できます。
__CAPGO_KEEP_1__
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
__CAPGO_KEEP_0__を解除します。__CAPGO_KEEP_0__を解除すると、デバイスの位置に応じて画面が回転できます。 また、motion-based orientation trackingも停止します。 注意: UIはユーザーの向きロック設定を尊重します。
__CAPGO_KEEP_1__
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();startOrientationTracking
__CAPGO_KEEP_3__を使用すると、デバイスの物理的な向きを独立して追跡できます。
画面の向きロックとは独立して向きの変化を検出できます。
iOSではCore Motionを使用して向きの変化を検出します。__CAPGO_KEEP_1__
__CAPGO_KEEP_4__
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
Section titled “stopOrientationTracking”モーションセンサを使用したデバイスの向きの追跡を停止します。
モーションセンサを使用したデバイスの向きの追跡を停止します。
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.stopOrientationTracking();isOrientationLocked
Section titled “isOrientationLocked”デバイスの向きのロックが現在有効かどうかを確認します。
このメソッドは、物理デバイスの向き(モーションセンサから)とUIの向きを比較します。 UIの向きと物理デバイスの向きが異なる場合、向きのロックは有効です。 Note: このメソッドは、startOrientationTracking()またはlock()でbypassOrientationLock: trueを指定することでモーション追跡を有効にする必要があります。 iOS(Core Motion)とAndroid(Accelerometer)両方で動作します。
コピー
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);}Section titled “Type Reference”
Section titled “ScreenOrientationResult”ScreenOrientationResult
Type Referenceorientation()メソッドによって返される結果
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
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
コピーデバイスの向きの状態を表す向きのタイプ
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';OrientationLockType
「向きのロックタイプ」のセクションデバイスの向きをロックするために使用できる向きのロックタイプ
export type OrientationLockType = | 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';真実の源
プラグインのpublic __CAPGO_KEEP_0__ がアップストリームで変更された場合に再度同期を実行してください。 src/definitions.ts. Re-run the sync when the public API changes upstream.
「Getting Started から続けて」のセクション
Capacitor を使用している場合If you are using Getting Started nativeアプリのメディアとインターフェイスの動作を計画するには、 @capgo/capacitor-screen-orientationを使用します。 @capgo/capacitor-screen-orientationのnative機能を使用します。 @capgo/capacitor-live-activitiesを使用します。 @capgo/capacitor-live-activitiesのnative機能を使用します。 @capgo/capacitor-live-activities @capgo/capacitor-live-activitiesの実装詳細です。 @capgo/capacitor-video-playerを使用します。 @capgo/capacitor-video-playerのnative機能を使用します。 @capgo/capacitor-video-player @capgo/capacitor-video-playerの実装詳細です。