App端强制横屏需双端原生配置:iOS在manifest.json设app-plus.distribute.ios.orientation为数组["landscape-primary","landscape-secondary"],并手动修改Info.plist添加UISupportedInterfaceOrientations;Android在manifest.json设app-plus.distribute.android.orientation为"landscape"字符串,并在AndroidManifest.xml中每个activity添加android:screenOrientation="landscape"。

manifest.json 必须双端分别配 orientation
App 端强制横屏不是“设一个值就完事”,iOS 和 Android 的配置项互不兼容,漏掉任一端都会导致真机失效。
必须在 manifest.json 的 app-plus.distribute.ios.orientation 下填数组:["landscape-primary", "landscape-secondary"];填 "landscape" 或单个字符串会被 iOS 忽略。
Android 对应位置是 app-plus.distribute.android.orientation,只接受字符串:"landscape"(不区分主次,也不能写数组)。
- 改完不删
unpackage目录、不重新云打包或重装自定义基座,真机上 100% 不生效 - pages.json 里的
pageOrientation对 App 端完全无效,别往那里写 - H5 和小程序也无视这个配置,它们走的是各自平台规则,和 App 配置无关
iOS 还得手动改 Info.plist
manifest.json 只是“指令”,真正起作用的是原生层。iOS 必须打开 unpackage/res/ios/Info.plist,手动添加:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
缺任意一项,iOS 真机就会退回到竖屏或旋转异常;模拟器常不准,务必用真机验证。
- 如果项目用了 iPad 支持,还得检查
UISupportedInterfaceOrientations~ipad是否同步配置 - Info.plist 修改后,不重新打包,Xcode 构建时仍读旧缓存
Android 必须检查每个 Activity 的 screenOrientation
Android 端不能只靠 manifest.json,必须打开 unpackage/res/android/AndroidManifest.xml,找到所有 <activity> 标签(包括主 Activity 和 subNVue 页面对应的 Activity),每个都加上:
android:screenOrientation="landscape"
漏掉任何一个 activity,对应页面就会竖屏显示或方向错乱。
- 如果用了自定义启动页、SplashActivity 或原生插件引入的 Activity,同样要加
- 若已硬编码
screenOrientation,uni.setScreenOrientation就彻底失效,别白费力气调用
别信 uni.setScreenOrientation 在 App 端能锁屏
这个 API 在 App 端不是“偶尔失效”,而是有明确边界:iOS 真机调用后静默失败,返回 { result: 'fail', errMsg: '' };Android 要求 targetSdkVersion ≥ 28 且 activity 未锁定方向才可能成功。
- 它只在当前 activity 生效,跳转新页面后方向重置,无法继承
- 想实现“首页竖屏 + 游戏页横屏”,纯 Vue 页面做不到;唯一可靠路径是把横屏页做成独立 activity(如用 subNVue 或原生插件)
- 所谓 CSS rotate 模拟横屏,会导致触摸坐标错位、Canvas 拉伸、键盘弹出异常——系统仍认为是竖屏,WebView 容器没真正横过来


















