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?

在纵向模式下设置我的应用程序样式后,我发现如果用户操纵他们的 phone 将应用程序调用到横向模式,它的布局是不可接受的。我可以稍后再 rewrite/retest 纵向和横向模式的用户体验,但暂时是我们让我们的应用程序一直保持纵向模式的方法吗?

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

Android

参考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 将包含这些更改。