[仅针对首次在AppDelegate.m iOS中设置启动方向

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

我正在将该库用于我的本机项目: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语句中的内容

ios swift react-native orientation screen-orientation
1个回答
0
投票

native-orientation是一个很好的库,用于检测和设置设备的方向。如您所见,文档具有解锁所有方向的属性。即; orientation.unlockAllOrientations()

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

componentDidMount(){

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

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

希望这对您有帮助。...

© www.soinside.com 2019 - 2024. All rights reserved.