指南
屏幕方向的教程
使用 @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-屏幕方向/
- 文档: /docs/plugins/屏幕方向/
继续使用 @capgo/capacitor-屏幕方向
如果您正在使用 使用 @capgo/capacitor-屏幕方向 为了规划原生媒体和界面行为,连接它与 @capgo/capacitor-screen-orientation 关于@capgo/capacitor-screen-orientation的实现细节在 Getting Started 关于Getting Started的实现细节在 使用@capgo/capacitor-live-activities 关于使用@capgo/capacitor-live-activities的原生能力在 @capgo/capacitor-live-activities 关于@capgo/capacitor-live-activities的实现细节在 使用@capgo/capacitor-video-player 关于使用@capgo/capacitor-video-player的原生能力在