使用@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/
继续使用@capgo/capacitor-screen-orientation
如果您正在使用 使用@capgo/capacitor-screen-orientation 来规划原生媒体和界面行为,连接它与 @capgo/capacitor-screen-orientation 为 @capgo/capacitor-屏幕方向 的实现细节 开始使用 为 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-实时活动 的实现细节 为 @capgo/capacitor-实时活动 的原生能力 @capgo/capacitor-实时活动 为 @capgo/capacitor-实时活动 的实现细节,以及 使用 @capgo/capacitor-视频播放器 为使用 @capgo/capacitor-视频播放器 的原生能力 for the native capability in Using @capgo/capacitor-video-player.