2013-03-13 49 views
1

所以我有一个导航控制器的应用程序,最后一个viewcontoller可以旋转到任何方向。其他人必须只有肖像。所以当我们在风景中旋转最后一个viewController然后按下导航控制器上的按钮时,我遇到了麻烦。我们转到前一个,看看布局是否坏了。 我认为唯一的办法就是用这样的:iOs 6从横向UIViewController返回到纵向

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

(我知道这是一个黑客,将优选避免这样的事情) 但无论我尝试它 - 它使我有不同的布局问题。通常的方法如:

- (NSUInteger)supportedInterfaceOrientations 
- (BOOL)shouldAutorotate 

等等的手柄方向在这种情况下是无用的。 在此先感谢。

回答

0

我解决了这个问题对于那些viewControllers的父母谁必须在纵向:

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

对于旋转的viewController:

-(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; 
} 
相关问题