huh519
huh519
  • 发布:2025-12-27 11:57
  • 更新:2025-12-27 12:16
  • 阅读:24

nvue工程如何配置手机强制竖屏,Pad强制横屏?

分类:nvue

如题:

想请教下,关于区分设备类型横竖屏的配置,在 Xcode 里是可以分别配置的:

uniapp 里也看到了有类似配置,manifest 的 screenOrientation:

和 page.json 里的 pageOrientation

但 pageOrientation 只能设置成竖屏,横屏或者 auto,无法像 Xcode 那样对 Phone 和 Pad 分别设置横竖屏,所以应该怎么做才能配置 Phone 强制竖屏,Pad 强制横屏呢?

2025-12-27 11:57 负责人:无 分享
已邀请:
Ask小助手

Ask小助手

该问题请在专业群( uni-app 官方技术交流群 1 ) 咨询,群中有相关专业的管理员和群友。

在 uni-app 中,manifest.json 的 screenOrientation 和 page.json 的 pageOrientation 无法直接区分设备类型设置横竖屏。但可以通过修改 iOS 原生配置文件实现:

  1. 在 manifest.json 中:先配置基础方向(如 ["portrait-primary", "landscape-primary"]),确保应用支持多方向
  2. 自定义 Info.plist:在 app-plus -> ios 配置中添加 InfoPlist 字段,分别设置 iPhone 和 iPad 的横竖屏支持列表:
"app-plus": {  
  "ios": {  
    "InfoPlist": {  
      "UISupportedInterfaceOrientations~iphone": [  
        "UIInterfaceOrientationPortrait"  
      ],  
      "UISupportedInterfaceOrientations~ipad": [  
        "UIInterfaceOrientationLandscapeLeft",  
        "UIInterfaceOrientationLandscapeRight"  
      ]  
    }  
  }  
}
  • UISupportedInterfaceOrientations~iphone 仅保留竖屏(UIInterfaceOrientationPortrait
  • UISupportedInterfaceOrientations~ipad 仅保留横屏方向

此方法利用了 iOS 原生特性,通过设备后缀区分配置。参考文档:iOS原生应用配置文件

注意:uni-app x 4.28+ 版本已修复 iPad 横竖屏适配问题(ISSUE#8991),建议升级到最新版。

内容为 AI 生成,仅供参考
huh519

huh519 (作者)

结贴,发现了这个文档:
https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-ios.html#orientation

加个 Info.plist 的原生配置文件就可以分别设置手机和 Pad 端的横竖屏了

要回复问题请先登录注册