2

我有这个设置来支持我的大多数视图控制器中的横向方向

我的应用程序委托有这段代码:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
 {
     NSUInteger orientations = UIInterfaceOrientationMaskLandscape;
    if (self.window.rootViewController) {
        UIViewController * pressented = [[((UINavigationController *)self.window.rootViewController) viewControllers] lastObject];
        orientations =[pressented supportedInterfaceOrientations];
    }
    return orientations;
 }

在大多数视图控制器中:

-(NSUInteger)supportedInterfaceOrientations
 {
    return UIInterfaceOrientationMaskLandscape;
 }

当我推动这个控制器(我想旋转的那个)时,我的问题就来了:

-(NSUInteger)supportedInterfaceOrientations
 {
    return UIInterfaceOrientationMaskALL;
 }

它完美地旋转但是当我以纵向方向弹出视图控制器(点击导航栏的后退按钮)时,呈现的视图控制器也将其方向设置为纵向。

如何使呈现的视图控制器保持锁定在横向上,或强制有问题的控制器在弹出之前旋转回横向。

4

1 回答 1

1

将此添加到您的纵向视图控制器:

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    UIViewController* dummyController = [[UIViewController alloc] init];
    [self presentViewController:dummyController animated:NO completion:^{
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}

我知道这是一个黑客,但它有效。有人知道更好的解决方案吗?

于 2013-04-11T22:23:03.583 回答