锁定和解锁ViewController旋转目标C.

时间:2016-01-15 09:46:19

标签: ios objective-c viewcontroller

默认情况下,我的应用仅限于纵向,但在一个 ViewController 中,我想根据某些操作锁定和解锁旋转。 在Android版本中,我使用带有FULL_SENSOR或 PORTRAIT LANDSCAPE 值的Activity.setRequestOrientation执行此任务。 哪个在iOS中等效?

由于

4 个答案:

答案 0 :(得分:0)

只需点击 xcode 中的项目属性,然后选择并取消选中复选框即可直接停止定位。(例如 PORTRAIT LANDSCAPE

点击xcode中的主项目,然后点击常规部分,您将获得此选项。

答案 1 :(得分:0)

您可以在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>

使用此功能,您可以根据需要添加方向支持,也可以防止特定屏幕的方向支持。

答案 2 :(得分:0)

AppDelegate.m

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

答案 3 :(得分:0)

您可能需要参考此答案here

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