在一个视图控制器中强制横向方向

mdo*_*ati 2 auto-rotation ios7

在iOS 5和6中,我在视图控制器的viewWillAppear方法中执行此操作:

UIViewController *c = [[UIViewController alloc] init];
//To avoid the warning complaining about the view not being part of the window hierarchy
[[[TWNavigationManager shared] window] addSubview:c.view];
[self presentModalViewController:c animated:NO];
[self dismissModalViewControllerAnimated:NO];
[c.view removeFromSuperview];
Run Code Online (Sandbox Code Playgroud)

我还在app委托中添加了此方法

- (NSUInteger)application:(UIApplication *)application      supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return [[TWNavigationManager shared] supportedInterfaceOrientationsForTopViewController];
}
Run Code Online (Sandbox Code Playgroud)

这基本上转发了对顶视图控制器的调用.

这导致我的视​​图控制器调用自动旋转方法,然后我能够强制该视图控制器的横向方向.现在在iOS 7中,该代码不再起作用了.全屏显示白色视图.

iOS7中的正确方法是什么?

提前致谢.

小智 5

有同样的问题,并通过解除动画的呈现模态视图设法解决它:是.

[self dismissViewControllerAnimated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

希望有所帮助!