旧时光
旧时光
  • 发布:2025-06-27 11:16
  • 更新:2025-07-04 15:35
  • 阅读:129

同一套代码、一个app,怎么做到在ipad(平板端)可以切换横竖屏,手机端只能竖屏

分类:uni-app

在manifest.json--app-plus节点中添加下面代码,ipad端支持横屏和竖屏了,但是手机端plus.screen.lockOrientation('portrait-primary'); // 锁定竖屏这个就失效了,也可以横竖屏旋转了。如果给screenOrientation中只配置portrait-primary这个,手机端竖屏了,但是ipad(平板)方向不能横屏了,求助大家,看怎么解决。

"screenOrientation": [  
        "portrait-primary",     //可选,字符串类型,支持竖屏  
        "portrait-secondary",   //可选,字符串类型,支持反向竖屏  
        "landscape-primary",    //可选,字符串类型,支持横屏  
        "landscape-secondary"   //可选,字符串类型,支持反向横屏  
    ],
2025-06-27 11:16 负责人:无 分享
已邀请:
DCloud_App_Array

DCloud_App_Array

不要在manifest.json中配置screenOrientation信息,在项目下添加Info.plist文件,配置以下内容:

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
<plist version="1.0">  
<dict>  
    <key>UISupportedInterfaceOrientations~iphone</key>  
    <array>  
        <string>UIInterfaceOrientationPortrait</string>  
    </array>  
    <key>UISupportedInterfaceOrientations~ipad</key>  
    <array>  
        <string>UIInterfaceOrientationPortrait</string>  
        <string>UIInterfaceOrientationPortraitUpsideDown</string>  
        <string>UIInterfaceOrientationLandscapeLeft</string>  
        <string>UIInterfaceOrientationLandscapeRight</string>  
    </array>  
</dict>  
</plist>
  • 旧时光 (作者)

    感谢回复,我试了这个方法,没有生效,重新打包了,是还需要啥配置吗

    2025-06-27 16:36

  • 旧时光 (作者)

    回复 旧时光: 哈哈,我知道了,你写错了,正确写法详见:https://uniapp.dcloud.net.cn/tutorial/app-nativeresource-ios.html#orientation

    2025-06-27 16:59

iOSDeveloper

iOSDeveloper - 专注于iOS相关领域 QQ:752562065

需要自行判断限制

  • 旧时光 (作者)

    请问一下,自行判断权限是什么意思

    2025-06-30 09:43

旧时光

旧时光 (作者) - 我是一位6年+前端开发的技术人员

我目前遇到的问题是,在项目根目录下添加了Info.plist文件,重新云打包了,但是不生效,手机端还是可以横屏

iOSDeveloper

iOSDeveloper - 专注于iOS相关领域 QQ:752562065

我下午到公司给你看一下,你加我一下QQ吧752562065

要回复问题请先登录注册