【问题标题】:iOs 6 return from UIViewController in landscape to portraitiOS 6 从 UIViewController 横向返回纵向
【发布时间】:2013-03-13 16:21:49
【问题描述】:

所以我有一个带有导航控制器的应用程序,最后一个视图控制器可以旋转到任何方向。其他人必须是纵向的。因此,当我们在横向旋转最后一个 viewController 然后按下导航控制器上的后退按钮时,我遇到了麻烦。我们转到上一个,看到布局被破坏了。 我认为唯一的方法是使用这样的东西:

[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait] 

(我知道这是一种黑客行为,最好避免此类事情) 但无论我在哪里尝试 - 它都给我带来了不同的布局问题。常用的方法如:

- (NSUInteger)supportedInterfaceOrientations
- (BOOL)shouldAutorotate

在这种情况下,用于句柄方向的等等都是无用的。 提前致谢。

【问题讨论】:

    标签: ios6 orientation uiinterfaceorientation


    【解决方案1】:

    我为那些必须是纵向的视图控制器的父级解决了这个问题:

    -(NSUInteger)supportedInterfaceOrientations{
     return UIInterfaceOrientationMaskPortrait;
    }
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
     return UIInterfaceOrientationPortrait;
    }
    - (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
     [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    }
    

    对于旋转视图控制器:

    -(NSUInteger)supportedInterfaceOrientations{
     return UIInterfaceOrientationMaskAll;
    }
    

    对于导航控制器:

    - (BOOL)shouldAutorotate {
    
    BOOL result = self.topViewController.shouldAutorotate;
    
     return result;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
    
    NSUInteger result = self.topViewController.supportedInterfaceOrientations;
    
    return result;
    }
    

    并将其添加到 AppDelegate:

    - (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    if ([navigationController.topViewController isKindOfClass:[RotationViewController  class]])
        return UIInterfaceOrientationMaskAll;
    else
        return UIInterfaceOrientationMaskPortrait;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      相关资源
      最近更新 更多