iOS手机上的锁定筛选方向

发布于 2025-01-23 07:48:28 字数 765 浏览 2 评论 0原文

我正在使用React-Navigation(Expo + Vscode + Windows)从一个屏幕导航到另一个屏幕,我必须将屏幕方向从肖像变为景观和环境。

仅通过使用选项(请参见下文),它在Android上完美工作,

<Stack.Screen
        name={MainFlowKeys.Home}
        component={Home}
        options={{ orientation: "portrait_up" }}
      />

但这对iOS不起作用。我使用物理设备对其进行测试(iPhone SE)。

因此,我尝试使用Expo模块(屏幕定位),但它是故障的(加载时屏幕旋转,但然后用户可以将其重新旋转,但未锁定)。

我正在使用此功能:

export const forceLandscape = async () => {
  await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT);
};

它在每个页面中都触发了:

  useEffect(() => {
    if (Platform.OS === "ios") forcePortrait();
  }, []);

但是它也不起作用(我的意思是屏幕旋转,但用户可以后来旋转它,但不会锁定)

如何解决此问题?我缺少什么?

I'm using react-navigation (expo + VScode + Windows) to navigate from one screen to another, and I have to change the screen orientation from portrait to landscape and the reverse way around.

It works perfectly on android, just by using the options (see below)

<Stack.Screen
        name={MainFlowKeys.Home}
        component={Home}
        options={{ orientation: "portrait_up" }}
      />

but this DOESN'T work on IOS. I use a physical device for testing it (iphone SE).

So I've tried to use an expo module (screen-orientation), but it's buggy (the screen is rotated when loaded but then the user can rotate it back afterward, it's not LOCKED).

I'm using this function:

export const forceLandscape = async () => {
  await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT);
};

It's trigerred in each page with:

  useEffect(() => {
    if (Platform.OS === "ios") forcePortrait();
  }, []);

but it doesn't work as well (I mean the screen rotates but the user can rotates it back afterward, it's NOT locked)

How to solve this? What is it I am missing ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文