2014-10-07 80 views
0

我正在使用UINavigationController的子类来管理我的应用程序的旋转。ios-视图控制器不会在当前方向加载

@implementation rotatingNavigationController 


- (BOOL)shouldAutorotate 
{ 
    return [self.topViewController shouldAutorotate]; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [self.topViewController preferredInterfaceOrientationForPresentation]; 
} 

在我的第一个观点我只允许纵向:

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

我推到用故事板创造了一个推赛格瑞一个新的视图控制器。新视图控制器支持所有的接口方向:

- (BOOL)shouldAutorotate 
{ 

    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskAll; 
} 

新的视图控制器总是加载在肖像,无论什么方向的装置被保持如果我身体后的设备变成纵向模式,并返回到景观。查看负载,它正确旋转。我该如何纠正这种情况,我需要视图加载视图时以何种方向加载设备?

+0

由于iOS6的我有很多的里面UINavigationController的不同取向的视图控制器的问题,并没有适当的解决办法已经找到。我试图避免这种情况,并以模态方式呈现景观视图控制器。 – hybridcattt 2014-10-07 11:02:09

回答

0

当你推新控制器。检查状态栏的interfaceorientation则:

-(BOOL)shouldAutorotate 
{ 
    if(isPushingViewVC) 
     return NO 
    return YES; 
} 

而且

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if(isPushingViewVC) 
    { 
     switch ([UIApplication sharedApplication].statusBarOrientation) 
     { 
      case UIInterfaceOrientationLandscapeLeft: 
       return UIInterfaceOrientationMaskLandscapeLeft; 
       break; 
      case UIInterfaceOrientationPortrait: 
       return UIInterfaceOrientationMaskPortrait; 
       break; 
      case UIInterfaceOrientationPortraitUpsideDown: 
       return UIInterfaceOrientationMaskPortraitUpsideDown; 
       break; 
      default: 
       return UIInterfaceOrientationMaskLandscape; 
       break; 
     } 
    } 
    return UIInterfaceOrientationMaskAll; 
} 
相关问题