gpt4 book ai didi

ios - 仅在 AppDelegate.m iOS 中首次启动时设置特定方向

转载 作者:行者123 更新时间:2023-11-29 05:25:56 25 4
gpt4 key购买 nike

我正在将此库用于我的 React Native 项目:

react-native-orientation-locker

我想要实现的目标是在除一个屏幕之外的所有屏幕上锁定方向为纵向。这个库工作正常,除非用户在横向模式下关闭应用程序,然后尝试在仍处于横向模式下打开它。在很短的时间内,应用程序以横向打开,然后旋转为纵向。但我不想看到这一点,相反,我想在启动时以纵向模式打开应用程序。

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

/*if (the app has just been launched) {
return UIInterfaceOrientationMaskPortrait;
}*/

// else, use the library to manage and set orientation
return [Orientation getOrientation];
}

我不知道如何检查第一次启动以及在上面的 if 语句中添加什么内容

最佳答案

native-orientations 是一个非常好的库,用于检测和设置设备的方向。正如您在文档中看到的,有属性可以解锁所有方向。 IE; orientation.unlockAllOrientations()

您可以在 componentWillUnmount/中使用它来获取应用程序的当前状态,并在应用程序进入后台时调用该函数,否则它将强制解锁所有方向,之后您可以在组件安装时将方向设置为肖像主文件,如 app.js。

componentDidMount() {

    Orientation.lockToPortrait(); // <----- This will reset stuff before the first unlock
}

componentWillUnmount() {
Orientation.unlockAllOrientations();
Orientation.lockToPortrait();
}

希望这对你有帮助......

关于ios - 仅在 AppDelegate.m iOS 中首次启动时设置特定方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58172476/

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