Ios6 iOs 6从UIViewController横向返回纵向

Ios6 iOs 6从UIViewController横向返回纵向,ios6,orientation,uiinterfaceorientation,Ios6,Orientation,Uiinterfaceorientation,所以我有一个带有导航控制器的应用程序,最后一个viewcontoller可以旋转到任何方向。其他的只能是肖像。所以,当我们在横向旋转最后一个viewController,然后按下导航控制器上的后退按钮时,我遇到了麻烦。我们转到上一个,看到布局被破坏了。 我想唯一的办法就是使用这样的东西: [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInter

所以我有一个带有导航控制器的应用程序,最后一个viewcontoller可以旋转到任何方向。其他的只能是肖像。所以,当我们在横向旋转最后一个viewController,然后按下导航控制器上的后退按钮时,我遇到了麻烦。我们转到上一个,看到布局被破坏了。 我想唯一的办法就是使用这样的东西:

[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait] 
(我知道这是一种黑客行为,最好避免这样的事情) 但无论我在哪里尝试,它都会给我带来不同的布局问题。通常的方法如下:

- (NSUInteger)supportedInterfaceOrientations
- (BOOL)shouldAutorotate
在这种情况下,手柄方向等都是无用的。
提前感谢。

我为那些必须处于纵向的ViewController的家长解决了这个问题:

-(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;
}
对于导航控制器:

-(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;
}