更新记录
1.0.1(2026-03-29)
增加获取当前屏幕是竖向时还是横向
1.0.0(2026-03-29)
ios旋转屏幕
平台兼容性
uni-app(4.87)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | iOS插件版本 | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | √ | × | 13 | 1.0.1 | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
uni-app x(4.87)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | × | 13 | × | × |
dui-rotate
uni-app x 下通过 UTS 在 App Android / App iOS 动态切换横竖屏的插件(iOS 使用 UTS 原生混编 Swift)。
在页面中引入
import {
setAppScreenOrientation,
setLandscape,
setPortrait,
setOrientationSensor,
getScreenOrientation
} from '@/uni_modules/dui-rotate'
API
| 方法 | 说明 |
|---|---|
setLandscape() |
固定横屏 |
setPortrait() |
固定竖屏 |
setOrientationSensor() |
跟随传感器(等价于 setAppScreenOrientation('sensor')) |
setAppScreenOrientation(mode: string) |
按模式设置,见下表 |
getScreenOrientation(): string |
读取当前界面朝向,返回 'portrait' 或 'landscape'(反向竖屏仍归 portrait,反向横屏仍归 landscape) |
mode 可选值:portrait、landscape、reverse-portrait、reverse-landscape、sensor、sensor-portrait、sensor-landscape、full-sensor、user、nosensor(与 Android ActivityInfo / iOS 掩码对应,部分语义在 iOS 上略有差异)。
建议在用户点击等交互里调用,避免在页面极早生命周期里调用。
uvue 示例
<script setup lang="uts">
import { setLandscape, setPortrait, setOrientationSensor, getScreenOrientation } from '@/uni_modules/dui-rotate'
function onLandscape() {
setLandscape()
}
function onPortrait() {
setPortrait()
}
function onSensor() {
setOrientationSensor()
}
function onReadOrientation() {
const o = getScreenOrientation()
console.log('当前朝向', o)
}
</script>

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 0
赞赏 0
下载 11668376
赞赏 1895
赞赏
京公网安备:11010802035340号