我怎么能只为一个viewController iOS做横向禁用

时间:2014-11-09 16:35:47

标签: ios orientation

我的项目有UITabbar,UınavigationBar和UIViewContoller。

-UITabbar
 —UINavigationController
   —UIViewController

问题:我怎么能做横向禁用一个viewController?我想只是纵向视图,但只想一个视图。

1 个答案:

答案 0 :(得分:4)

<击> disable autorotate on a single UIViewController in iOS6

<击>

将此添加到您的应用代理

- (NSUInteger) application:(UIApplication *)application     supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if ([[window.rootViewController presentedViewController] isKindOfClass:[YourViewController class]])
    return UIInterfaceOrientationMaskPortrait;
else
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

<击> 编辑2

我最近发现了这一点,它一直对我很有用。将此代码添加到视图控制器

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

并在viewWillAppear添加

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    ///Disable orientation changes
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}