锁定和解锁视图控制器旋转目标 C



我的应用程序默认仅处于纵向,但在一个视图控制器中,我想通过某些操作锁定和解锁旋转功能。在Android版本中,我使用带有FULL_SENSOR或PORTRAITLANDSCAPE值的Activity.setRequestOrientation来完成此任务。iOS 中哪个是等效的?

谢谢

您可以在 xcode 项目的 info.plist 文件中添加 iPhone 和 iPad 特定的方向支持在源代码模式下打开您的 info.pList 并添加此内容

<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

使用它,您可以添加所需的任何屏幕的方向支持,还可以防止对特定屏幕的方向支持。

您可以通过选中和取消选中复选框来单击 xcode 中的项目属性来直接停止方向。例如纵向横向

单击Xcode中的主项目,然后在"常规"部分中,您将获得此选项。

在你的AppDelegate.m中:

-(UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (self.allowRotation)
    {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }
}

你可能想在这里参考这个答案。

上面的每个人,问题是关于特定的控制器方向锁定,而不是全部。

最新更新