2013-05-27 35 views
1

我有UITabBarController子類處理旋轉問題:的UITabBarController presentmodal自動旋轉問題

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
    return YES; 
} 

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

-(BOOL)shouldAutorotate{ 
    return YES; 
} 
tabbatcontrollerUIViewController的一個

,現在我提出一個新的UIViewController

MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil]; 
UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC]; 

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:mainNav animated:YES]; 

而且在這個新的導航,我想禁用自動旋轉,只允許肖像:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

-(BOOL)shouldAutorotate{ 
    return NO; 
} 

但旋轉仍然工作,當我旋轉屏幕的應用程序轉到橫向屏幕,我該如何解決這個問題?

+0

您需要檢查每一次當前設備的方向或設備狀態欄始發: - 請檢查我的答案: - http://stackoverflow.com/questions/16710899/force-portrait-in-one-view-controller-makes-other-to-be-in-portrait -initially/16711127#16711127 –

回答

1

你也應該繼承UINavigationController並把下面的代碼在你的子類:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // You do not need this method if you are not supporting earlier iOS Versions 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

然後,初始化您的子類的實例:

MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil]; 
MYSubclassedNavigationController *mainNav = [[MYSubclassedNavigationController alloc] initWithRootViewController:mainVC]; 

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
[self presentModalViewController:mainNav animated:YES]; 
+0

謝謝!有效 – MTA