我想知道是否可以在 iOS 和 Android 上锁定所有屏幕,除了一个屏幕。我有一个视频播放器,我想在旋转后全屏显示,但所有其他屏幕都必须是唯一的纵向。
我为此使用 react-native-video 。
使用示例时我设法让它旋转,但我需要在 XCODE 和 Android studio 中设置可能的方向。
我还尝试了 react-native-orientation 并在其上放置了一个 .lockToPortrait() 但在倾斜后,它再次发生变化。
任何帮助表示赞赏
最佳答案
const {navigation} = props
useEffect(() => {
navigation.addListener("focus", () => {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.DEFAULT);
});
navigation.addListener("blur", () => {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT);
});
}, [navigation]);
focus
当我们想要允许屏幕旋转的屏幕和 blur
时触发事件当用户离开包含此代码的屏幕时触发事件,然后限制为 PORTRAIT(在这种情况下)。
关于react-native - react native : Allow only a certain screen to change orientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54715043/