如题:
想请教下,关于区分设备类型横竖屏的配置,在 Xcode 里是可以分别配置的:
uniapp 里也看到了有类似配置,manifest 的 screenOrientation:
和 page.json 里的 pageOrientation
但 pageOrientation 只能设置成竖屏,横屏或者 auto,无法像 Xcode 那样对 Phone 和 Pad 分别设置横竖屏,所以应该怎么做才能配置 Phone 强制竖屏,Pad 强制横屏呢?
该问题请在专业群( uni-app 官方技术交流群 1 ) 咨询,群中有相关专业的管理员和群友。
在 uni-app 中,manifest.json 的 screenOrientation 和 page.json 的 pageOrientation 无法直接区分设备类型设置横竖屏。但可以通过修改 iOS 原生配置文件实现:
["portrait-primary", "landscape-primary"]),确保应用支持多方向 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),建议升级到最新版。
huh519 (作者)
结贴,发现了这个文档:
https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-ios.html#orientation
加个 Info.plist 的原生配置文件就可以分别设置手机和 Pad 端的横竖屏了