繁体   English   中英

即使用户在横向模式下旋转他们的设备,是否在 Gluon API 中让我们的应用程序保持纵向模式?

[英]Is it in the Gluon API to keep our app in Portrait Mode even if the user rotates their device in Landscape Mode?

在以纵向模式设置我的应用程序样式后,我发现如果用户操作他们的手机将应用程序调用到横向模式,它的布局是不可接受的。 我可以稍后花时间重写/重新测试纵向和横向模式的用户体验,但暂时是我们让我们的应用程序始终保持纵向模式的一种方式?

目前还没有 API 或附加服务。 但是,您可以修改 AndroidManifest.xml 文件 (Android) 或 Default-Info.plist 文件 (iOS) 以强制单一方向,而不是现有的纵向和横向方向。

安卓

请参阅https://docs.gluonhq.com/#_android_2以供参考。

AndroidManifest.xml 文件是为具有 gluonfx:package 目标的项目生成的,它位于 target/gluonfx/aarch64-android/gensrc/android。

将此文件复制到src/android并进行所需的任何修改:

  • 肖像
<?xml version='1.0'?>
<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='$your_package' android:versionCode='1' android:versionName='1.0'>
    <application android:label='$your_label' android:icon="@mipmap/ic_launcher">
        <activity android:name='com.gluonhq.helloandroid.MainActivity'
    android:configChanges="orientation|keyboardHidden" 
    android:screenOrientation="portrait">
             <intent-filter>
                <category android:name='android.intent.category.LAUNCHER'/>
                <action android:name='android.intent.action.MAIN'/>
             </intent-filter>
        </activity>
</manifest>
  • 风景
<?xml version='1.0'?>
<manifest xmlns:android='http://schemas.android.com/apk/res/android' package='$your_package' android:versionCode='1' android:versionName='1.0'>
    <application android:label='$your_label' android:icon="@mipmap/ic_launcher">
        <activity android:name='com.gluonhq.helloandroid.MainActivity' 
    android:configChanges="orientation|keyboardHidden" 
    android:screenOrientation="landscape">
             <intent-filter>
                <category android:name='android.intent.category.LAUNCHER'/>
                <action android:name='android.intent.action.MAIN'/>
             </intent-filter>
        </activity>
</manifest>

然后再次运行gluonfx:package ,最终清单将包含更改。

IOS

请参阅https://docs.gluonhq.com/#_ios_2以供参考。

配置由键UISupportedInterfaceOrientationsUISupportedInterfaceOrientations-ipad 默认值:

        <key>UISupportedInterfaceOrientations</key>
        <array>
                <string>UIInterfaceOrientationPortrait</string>
                <string>UIInterfaceOrientationLandscapeLeft</string>
                <string>UIInterfaceOrientationLandscapeRight</string>
                <string>UIInterfaceOrientationPortraitUpsideDown</string>
        </array>
        <key>UISupportedInterfaceOrientations~ipad</key>
        <array>
                <string>UIInterfaceOrientationPortrait</string>
                <string>UIInterfaceOrientationLandscapeLeft</string>
                <string>UIInterfaceOrientationLandscapeRight</string>
                <string>UIInterfaceOrientationPortraitUpsideDown</string>
        </array>

添加文件src/main/resources/META-INF/substrate/ios/Partial-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</key>
        <array>
                <string>UIInterfaceOrientationPortrait</string>
                <string>UIInterfaceOrientationPortraitUpsideDown</string>
        </array>
        <key>UISupportedInterfaceOrientations~ipad</key>
        <array>
                <string>UIInterfaceOrientationPortrait</string>
                <string>UIInterfaceOrientationPortraitUpsideDown</string>
        </array>
</dict>
</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</key>
        <array>
                <string>UIInterfaceOrientationLandscapeLeft</string>
                <string>UIInterfaceOrientationLandscapeRight</string>
        </array>
        <key>UISupportedInterfaceOrientations~ipad</key>
        <array>
                <string>UIInterfaceOrientationLandscapeLeft</string>
                <string>UIInterfaceOrientationLandscapeRight</string>
        </array>         
</dict>
</plist>

然后再次运行mvn gluonfx:link ,最终的 plist 将包含这些更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM