@capgo/capacitor-screen-orientationを使用します
Capacitor画面向きプラグインインターフェイス
インストール
bun add @capgo/capacitor-screen-orientation
bunx cap sync
このプラグインが公開するもの
orientation- 現在の画面向きを取得します。lock- 画面向きを特定のタイプに固定します。unlock- 画面向きを解除します。startOrientationTracking- デバイスの向きをモーションセンサを使用して追跡します。
使用例
orientation
現在の画面向きを取得します。
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
const result = await ScreenOrientation.orientation();
console.log('Current orientation:', result.type);
lock
特定の方向に画面の向きを固定する
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
});
unlock
画面の向きを解除する
import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
await ScreenOrientation.unlock();
startOrientationTracking
モーションセンサを使用してデバイスの向きを追跡する
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);
});
フルリファレンス
- GitHub https://github.com/Cap-go/capacitor-screen-orientation/
- ドキュメント: /docs/plugins/screen-orientation/
Using @capgo/capacitor-screen-orientationから続ける
__CAPGO_KEEP_0__を使用している場合 Using @capgo/capacitor-screen-orientation __CAPGO_KEEP_0__/__CAPGO_KEEP_1__-screen-orientationを使用してネイティブのメディアとインターフェイスの動作を計画する場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-screen-orientationと接続する capgo/capacitor-screen-orientationを使用している場合 実装詳細については @capgo/capacitor-screen-orientation に Getting Started 実装詳細については Getting Started に Using @capgo/capacitor-live-activities Using @capgo/capacitor-live-activities のネイティブ機能については @capgo/capacitor-live-activities 実装詳細については @capgo/capacitor-live-activities に Using @capgo/capacitor-video-player Using @capgo/capacitor-video-player のネイティブ機能については