简体   繁体   English

如何为 React Native 锁定设备方向

[英]How to lock device orientation for React Native

Hi I want to know how to lock device orientation for React Native for both android and iOS.嗨,我想知道如何为 android 和 iOS 的 React Native 锁定设备方向。 I need to lock the orientation once user rotate the device and application will lock with portrait or lanscape一旦用户旋转设备,我需要锁定方向,应用程序将锁定纵向或横向

For Android安卓版

For Android platform all we need to do is navigate to AndroidManifest.xml file that lies inside android/app/src/main path and add the property android:screenOrientation with a value or portrait or landscape respectively.对于 Android 平台,我们需要做的就是导航到位于android/app/src/main路径内的AndroidManifest.xml文件,并分别添加属性android:screenOrientation与值或纵向横向 The property has to be added in xml element activity which is a child of application element.该属性必须添加到 xml 元素活动中,该活动是应用程序元素的子元素。

Simply add it as shown below:只需添加它,如下所示:

在此处输入图片说明

For iOS对于 iOS

For iOS platform we need to open Xcode, and select the desired orientation modes from the Device Orientation section.对于 iOS 平台,我们需要打开 Xcode,然后从 Device Orientation 部分选择所需的方向模式。 As shown below:如下所示:

  1. Load the iOS part of your React Native project加载 React Native 项目的 iOS 部分
  2. Navigate to tab General from the horizontal menu从水平菜单导航到选项卡 General
  3. Go to down to Deployment Info section and check/uncheck the desired device orientation modes.转到部署信息部分并选中/取消选中所需的设备方向模式。

在此处输入图片说明

And you are set!你已经准备好了! Rebuild your project to verify that the changes are configured.重建您的项目以验证更改是否已配置。

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

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