当屏幕方向改变时,我只想旋转一个元素

问题描述 投票:0回答:0

我正在制作一个带有 react native、expo、bottom-tab-bar 导航包和 expo-screen-orientation 包的应用程序。

该应用程序用于阅读屏幕中间某些视图元素内的一些文本,并通过底部标签栏进行控制。

当我旋转手机并更改屏幕方向(纵向-横向)时,它有点混乱了 UI 布局。 我想要实现的是只有包含可读文本的 View 元素在手机改变方向时旋转,但应用程序的其余部分(底部标签栏、背景、按钮等)保留在“纵向”方向。

到目前为止我尝试过的是: 我试图将屏幕锁定为纵向

ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT); 然后使用 eventListeners、Dimentions、useWindowDimentions 和 expo-screen-orientation 的 ScreenOrientation.AddOrientationChangeListener(Listener) 监听方向变化, 然后可能手动旋转视图元素。

但如果屏幕被锁定且未旋转,则不会检测到变化。

我看过但找不到答案。

react-native expo mobile-application screen-orientation expo-screen-orientation
© www.soinside.com 2019 - 2024. All rights reserved.