更新记录

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 可选值portraitlandscapereverse-portraitreverse-landscapesensorsensor-portraitsensor-landscapefull-sensorusernosensor(与 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>

参考文档

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。