app端强制横屏必须修改原生配置并重新云打包:ios需在info.plist中添加两个固定字符串uiinterfaceorientationlandscapeleft和uiinterfaceorientationlandscaperight,android需为每个activity显式设置android:screenorientation="landscape",manifest.json已失效。

App 端强制锁定横屏不能靠 uni.setScreenOrientation,这个 API 在 iOS 真机上基本返回 { result: 'fail', errMsg: 'not supported' },Android 12+ 也常被系统拦截;真正起效的路径只有一条:修改原生配置并重新云打包。
iOS 必须改 Info.plist,填对两个固定字符串
iOS 不认 "landscape" 或数组里混写其他值,只接受且必须同时存在两个键值:
UIInterfaceOrientationLandscapeLeftUIInterfaceOrientationLandscapeRight
位置在 unpackage/res/ios/Info.plist,手动添加如下结构(不是字符串,是数组):
<key>UISupportedInterfaceOrientations</key><array><string>UIInterfaceOrientationLandscapeLeft</string><string>UIInterfaceOrientationLandscapeRight</string></array>
漏掉任一值、拼错大小写、或只写一个,都会导致横屏失效。别指望 manifest.json 自动补全——它不会写入这两个值。
Android 必须改 AndroidManifest.xml,每个 Activity 都要加
不是只改主 Activity,所有涉及的 <activity></activity> 标签(包括 subNVue 页面、自定义插件页面)都得显式加属性:
android:screenOrientation="landscape"
填 "sensorLandscape" 反而容易触发旋转异常;填 "portrait" 会直接锁死竖屏,覆盖一切 JS 调用。检查路径:unpackage/res/android/AndroidManifest.xml。若用自定义基座,还得确认基座自身的 AndroidManifest.xml 是否也被覆盖。
manifest.json 的配置只是“指令”,不等于生效
新版 uni-app(3.9+)已弃用 manifest.json 中 app-plus.distribute.ios.orientation 和 app-plus.distribute.android.orientation 字段。如果你还在用,它根本不会写入原生工程。
正确做法是直接编辑原生文件,然后:
- 删掉整个
unpackage目录 - 重新云打包,或生成新自定义基座
“运行到手机”热重载、HBuilderX 的调试按钮,完全不触发原生配置更新——这点最容易被忽略。
想只让某页面横屏?iOS 基本做不到纯 JS 实现
Android 可单独为某个 Activity 配 android:screenOrientation="landscape",再用 uni.navigateTo 跳过去;但 iOS 没有等价机制。纯 Vue 页面无法实现“首页竖屏 + 游戏页横屏”,除非:
- 游戏页用原生插件动态调用
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) forKey:@"orientation"] - 或把游戏页做成独立的、原生层已声明横屏的 ViewController
别试图用 transform: rotate(90deg) 模拟横屏——Canvas 尺寸错乱、触摸坐标偏移、键盘弹不出,游戏或视频页会直接不可用。











