gpt4 book ai didi

android - 使用 React Native 的纵向锁定 Android 应用程序中的方向感知模态

转载 作者:行者123 更新时间:2023-11-29 02:33:43 26 4
gpt4 key购买 nike

我正在开发一个 react native 应用程序,由于应用程序的性质,它通常被锁定为纵向。使用 AndroidManifest.xml 中的以下标志将应用锁定为纵向

android:screenOrientation="portrait"

现在我想让应用程序能够在应用程序的某个地方旋转。 react-native 中的 Modal 组件似乎是正确的选择。模态框配置如下:

<Modal
animationType="slide"
transparent={false}
supportedOrientations={['portrait', 'portrait-upside-down', 'landscape', 'landscape-left', 'landscape-right']}
>
<View style={styles.modal}>
<View>
<TouchableHighlight onPress={() => {
this.setState({
awareVisible: false
});
}}>
<Text>Hide Modal</Text>
</TouchableHighlight>
</View>
</View>
</Modal>

在 iOS 中这工作正常并且 View 会旋转,在 Android 中它不做任何事情。我尝试创建一个自定义模态组件并在 Android 代码中捕获它,但这对我也不起作用。

最佳答案

您可以使用 react-native-orientation 执行此操作...而且因为这个项目似乎不再维护,所以最好使用这个分支:react-native-orientation-locker

有了它,你只需要在需要的时候设置这样的东西:

Orientation.unlockAllOrientations(); //this will unlock the view to all Orientations
Orientation.lockToPortrait(); //this will lock the view to Portrait
Orientation.lockToLandscapeLeft(); //this will lock the view to Landscape

我还在我的一个强制为纵向模式的应用程序中使用了它。但是我需要横向模式来查看图像库的图像。在 Android 和 IOS 上都运行良好。

希望这对你有帮助。

关于android - 使用 React Native 的纵向锁定 Android 应用程序中的方向感知模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48221282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com