真机App横屏必须修改原生配置:iOS需在Info.plist中添加UISupportedInterfaceOrientations数组,含UIInterfaceOrientationLandscapeLeft和Right;Android需在AndroidManifest.xml各activity中设android:screenOrientation="landscape";改完必须删unpackage目录并重新云打包。

真机 App 横屏必须改原生配置,只动 manifest.json 或写 CSS 旋转,等于没设——触摸错位、Canvas 拉伸、键盘弹出异常全都会来。
manifest.json 配置只是“指令”,不是最终生效项
很多人以为在 manifest.json 的 app-plus → distribute 下填了 orientation 就完事了,其实这只是告诉 uni-app 编译器“我想横屏”,它会尝试注入到原生工程里。但 iOS 和 Android 实际是否执行,取决于你有没有手动补全那两个关键文件:
- iOS:必须打开
unpackage/res/ios/Info.plist,加及两个UISupportedInterfaceOrientations 值:UIInterfaceOrientationLandscapeLeft和UIInterfaceOrientationLandscapeRight - Android:必须打开
unpackage/res/android/AndroidManifest.xml,找到所有用到的(包括主页面、subNVue 页面、自定义插件对应的 activity),每个都加android:screenOrientation="landscape" - 漏掉任意一个
,对应页面就会退回到竖屏或旋转异常
pages.json 的 pageOrientation 仅对小程序和部分 App 场景有效
这个字段常被误当成“App 页面级横屏开关”,但它在 App 端实际作用很弱:
- 微信小程序必须同时配
pages.json的mp-weixin.pageOrientation和manifest.json的mp-weixin.settings.screenOrientation才可能生效 - App 端若只靠
pages.json里某页设"pageOrientation": "landscape",而manifest.json没配app-plus.distribute.ios/orientation,iOS 上大概率无效 - H5 完全忽略
pageOrientation,别在这儿浪费时间
plus.screen.lockOrientation 调用时机和平台限制极严
这个 API 看似灵活,但真机上极易失效,不是代码问题,是平台规则:
- 必须用
#ifdef APP-PLUS包裹,否则 H5 构建失败、小程序运行报错 - iOS 上必须在
onShow(不是onLoad)里调,且建议加setTimeout延迟 300ms,否则启动动画未结束时锁不住 - 值必须写标准枚举:
"landscape-primary"(home 键在右)或"landscape-secondary"(home 键在左),写"landscape"会被 iOS 忽略 - 锁完不调
plus.screen.unlockOrientation(),退出页面后方向会被卡住,影响后续页面
别碰 uni.setScreenOrientation,它在 App 端基本形同虚设
文档写了,但真机上几乎不可用:
- iOS WKWebView 层面直接拦截 JS 请求,调用后既不报错也不生效
- Android 12+ 系统同样拦截,部分低端机型能跑通,但无法作为兼容方案依赖
- 返回值是 Promise,但失败时 resolve 的是
{ result: 'fail', errMsg: 'xxx' },不检查就以为成功了 - 如果已在
AndroidManifest.xml中硬编码android:screenOrientation="landscape",这个 API 就完全无反应
真正起效的只有三件事:改 Info.plist、改 AndroidManifest.xml、重新云打包或换自定义基座。其他所有 JS 层操作,都是在原生配置已生效的前提下“锦上添花”,而不是“雪中送炭”。











