コンテンツにスキップ

画面の向き __CAPGO_KEEP_0__ リポジトリ

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

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

画面の向きを取得するデバイスの現在の向きを返します。

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

__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 lock
await ScreenOrientation.lock({ orientation: 'landscape' });
// Lock with motion tracking on iOS
await ScreenOrientation.lock({
orientation: 'portrait',
bypassOrientationLock: true
});

__CAPGO_KEEP_0__を解除すると、デバイスの位置に応じて画面が回転できます。 また、motion-based orientation trackingも停止します。 注意: UIはユーザーの向きロック設定を尊重します。

__CAPGO_KEEP_1__

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

__CAPGO_KEEP_1__

__CAPGO_KEEP_4__

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の向きを比較します。 UIの向きと物理デバイスの向きが異なる場合、向きのロックは有効です。 Note: このメソッドは、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);
}

Section titled “Type Reference”

Section titled “ScreenOrientationResult”

ScreenOrientationResult

Type Reference

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

コピー

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

デバイスの向きをロックするために使用できる向きのロックタイプ

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の実装詳細です。