【问题标题】:How to disable screen rotation (react-native)?如何禁用屏幕旋转(react-native)?
【发布时间】:2016-02-26 07:00:58
【问题描述】:

是否有机会禁用屏幕旋转(仅允许垂直)?我想只支持纵向视图。并且需要它在 android 和 ios 上工作。

【问题讨论】:

标签: javascript android ios react-native


【解决方案1】:

在您的 Manifest.xml 类中添加 screenOrientation

<activity android:name=".YourActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />

【讨论】:

    【解决方案2】:

    将以下代码放入清单文件中

    <activity
       android:screenOrientation="portrait"
       android:configChanges="orientation|keyboardHidden">
    </activity>

    【讨论】:

      【解决方案3】:

      在清单文件中写入以下代码

      <activity
         android:screenOrientation="portrait"
         android:configChanges="orientation|screenSize">
      </activity>
      

      【讨论】:

        【解决方案4】:

        在安卓中:-

        使用 xml :-android:screenOrientation="portrait"

        使用 java :-

        @Override 
        public void onCreate(Bundle savedInstanceState) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        

        【讨论】:

        • 请清楚你的答案,这个问题同时适用于 iOs 和 Android。
        【解决方案5】:

        获胜者:在应用程序代码中删除它,我通常在所有导入后立即将其丢弃。

        Expo.ScreenOrientation.allow(Expo.ScreenOrientation.Orientation.PORTRAIT);

        【讨论】:

          【解决方案6】:

          看看安卓官方documentation

          您只需将其添加到您的 android MANIFEST 文件中的活动标签中:

          <activity 
            android:screenOrientation=["unspecified" | "behind" |
              "landscape" | "portrait" |
              "reverseLandscape" | "reversePortrait" |
              "sensorLandscape" | "sensorPortrait" |
              "userLandscape" | "userPortrait" |
              "sensor" | "fullSensor" | "nosensor" |
              "user" | "fullUser" | "locked"]
          

          使用您想要的方向。

          【讨论】:

            【解决方案7】:

            尝试在config.xml中添加这个

            <preference name="Orientation" value="landscape" />
            

            【讨论】:

            • 这适用于 Cordova/Phonegap,不适用于 React Native。
            猜你喜欢
            • 2015-11-17
            • 2015-01-22
            • 1970-01-01
            • 1970-01-01
            • 2018-11-17
            • 1970-01-01
            • 2020-01-28
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多