manifest文件根据重力感应配置好竖屏选项后在uni-app中无法强制app启动时是竖屏

manifest文件根据重力感应配置好竖屏选项后在uni-app中无法强制app启动时是竖屏

信息项 内容
产品分类 uniapp/App
PC开发环境 Windows
PC开发环境版本 Windows 10 专业版19045.3570
手机系统 全部
页面类型 vue
vue版本 vue3
打包方式 云端
项目创建方式 CLI
CLI版本号 vue3+ts+vite的3.8.12.20230817

测试过的手机:

  • iphone7,系统为ios15.6
  • 红米k40s,系统为miui14.0.7,Android13

示例代码:

//重力感应配置以配置  
"app-plus": {  
    // 重力感应、横竖屏配置  
    "screenOrientation": [  
        "portrait-primary" //可选,字符串类型,支持竖屏  
    ],  
}

操作步骤:

  • 当手机为不锁定方向,横屏放置,启动的时候仍是横屏的,启动后才是竖屏,也就是存在一个横竖屏转换效果,并没有一直竖屏

预期结果:

  • 无论如何,重力感应下,app启动时和启动后都是竖屏

实际结果:

  • 重力横屏感应下,app启动会受重力感应横屏

bug描述:

  • 红米k40s设置了竖屏后,不锁定方向,启动的时候出现的横屏,启动后的竖屏录屏.zip

更多关于manifest文件根据重力感应配置好竖屏选项后在uni-app中无法强制app启动时是竖屏的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于manifest文件根据重力感应配置好竖屏选项后在uni-app中无法强制app启动时是竖屏的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在 UniApp 中,如果你已经通过 manifest.json 文件配置了应用为竖屏模式,但应用启动时仍然无法强制保持竖屏,可能是由于以下原因:

1. 检查 manifest.json 配置

确保在 manifest.json 文件中正确配置了应用的屏幕方向。例如:

{
  "app-plus": {
    "screenOrientation": [
      "portrait-primary",
      "portrait-secondary"
    ]
  }
}
  • portrait-primary 表示竖屏(主方向)。
  • portrait-secondary 表示竖屏(次方向,即倒置的竖屏)。

2. 检查平台差异

不同平台(如 iOS 和 Android)对屏幕方向的处理可能有所不同。确保你在 manifest.json 中为所有目标平台都配置了正确的屏幕方向。

3. 检查原生配置

在某些情况下,可能需要通过原生配置来强制应用保持竖屏。例如:

Android

AndroidManifest.xml 文件中,确保 activity 标签中配置了 screenOrientation 属性:

<activity
    android:name=".MainActivity"
    android:screenOrientation="portrait">
</activity>

iOS

Info.plist 文件中,确保配置了 UIInterfaceOrientation 相关键值:

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationPortrait</string>

4. 使用代码强制竖屏

如果通过配置文件无法解决问题,可以在应用启动时通过代码强制设置屏幕方向。例如:

// 在 App.vue 的 onLaunch 生命周期中调用
export default {
  onLaunch() {
    if (plus && plus.screen) {
      plus.screen.lockOrientation('portrait-primary');
    }
  }
}
回到顶部