ガイド
画面の向きに関するチュートリアル
Using @capgo/capacitor-screen-orientation
Capacitor 画面の向き プラグイン インターフェース
インストール
bun add @capgo/capacitor-screen-orientation
bunx cap sync
このプラグインが提供するもの
orientation- 現在の画面の向きを取得するlock- 画面の向きを特定のタイプに固定するunlock- 画面の向きを解除するstartOrientationTracking- __CAPGO_KEEP_0__ を使用したデバイスの向きを追跡する
Example Usage
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
Motion Sensor を使用したデバイスの向きを追跡する
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);
});
Full Reference
- GitHub https://github.com/Cap-go/capacitor-screen-orientation/
- Docs: /docs/plugins/screen-orientation/