在一个视图控制器中强制横向方向 [英] Force landscape orientation in one view controller
问题描述
在iOS 5和6中,我在视图控制器的viewWillAppear方法中执行此操作:
In iOS 5 and 6 I was doing this in the viewWillAppear method in my view controller:
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];
我还在app delegate中添加了此方法
I also added this method in the app delegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return [[TWNavigationManager shared] supportedInterfaceOrientationsForTopViewController];
}
这基本上转发了对顶视图控制器的调用。
Which basically forwards that call to the top view controller.
这导致我的视图控制器调用了自动旋转方法,然后我就可以强制该视图控制器的横向方向。
现在在iOS 7中,该代码不再起作用了。白色视图全屏显示。
That caused auto-rotation methods to be called for my view controller and then I was able to force landscape orientation for just that view controller. Now in iOS 7 that code doesn't work anymore. A white view appears full-screen.
iOS7中的正确方法是什么?
What would be the proper approach in iOS7?
提前致谢。
推荐答案
遇到同样的问题并设法通过解除所呈现的动态模态视图来修复它:是。
Had the same problem and managed to fix it by dismissing the presented modal view animated:YES.
[self dismissViewControllerAnimated:YES completion:nil];
希望有所帮助!
这篇关于在一个视图控制器中强制横向方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!