在iOS6中的单个UIViewController上禁用自动旋转 [英] disable autorotate on a single UIViewController in iOS6
问题描述
我有一个项目使用 UINavigationController
和 segues
工作正常,所有这些都正确旋转,事情是...我只想在特定的 UIViewController
上禁用 autorotation
。
我试过这个:
I have a project using UINavigationController
and segues
working properly good, all of them rotate correctly, the thing is... I just want to disable autorotation
on a specific UIViewController
.
I tried this:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
// New Autorotation support for iOS 6.
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0){
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
但它不起作用,我的 UIViewController
自动轮换,欢迎任何帮助:)
but it's not working, my UIViewController
keeps rotating automatically, any help will be welcome :)
推荐答案
根据View Controller编程指南
Per the View Controller Programing Guide
如果要暂时禁用自动旋转,请避免操作方向遮罩来执行此操作。而是覆盖初始视图控制器上的shouldAutorotate方法。在执行任何自动旋转之前调用此方法。如果它返回NO,则旋转被抑制。
If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the initial view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed.
所以你需要子类'UINavigationController',实现shouldAutorotate并在故事板中使用你的导航控制器类。
So you need to subclass 'UINavigationController', implement shouldAutorotate and use your navigation controller class in your storyboard.
- (BOOL)shouldAutorotate
{
id currentViewController = self.topViewController;
if ([currentViewController isKindOfClass:[DetailViewController class]])
return NO;
return YES;
}
这篇关于在iOS6中的单个UIViewController上禁用自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!