从视图控制器控制自动旋转,而无需修改应用程序的其余部分

时间:2014-03-24 23:12:55

标签: ios ios7 uiviewcontroller

我正在开发一个iOS框架。它包含一个视图控制器,可以由将使用我的框架的应用程序以模态方式显示。我无法访问应用程序代码,只能访问我的框架。我想在显示视图控制器时阻止自动旋转。可以这样做吗?我已尝试在我的VC中从NO返回shouldAutorotateToInterfaceOrientation:,但这不会被调用。

1 个答案:

答案 0 :(得分:0)

您可以将此代码添加到AppDelegate。它将允许其他viewControllers响应自动旋转调用。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
/* This is in order to allow views that do not support landscape mode to be able to load in
 */
return UIInterfaceOrientationMaskAll;
}

此外,在iOS 6.0及更高版本中,不推荐使用shouldAutorotateToInterfaceOrientation:方法。它可以用以下方法代替:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}
- (BOOL) shouldAutorotate{
    return YES;
}