2014-02-25 59 views
2

我有以下情形:IOS縱向和橫向模式

從的appDelegate我做的:

firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
    UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController]; 

firstViewController - 需要只在人像模式

爲了做到這一點我做了:

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

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait; 
} 

firstViewController我是推另一個視圖控制器需要具有縱向和橫向功能。

像預期的那樣secondViewController行爲 - 在波泰特和橫向模式

我有顯示在橫向模式也與firstViewController問題,雖然我已經將其限制在肖像模式。我究竟做錯了什麼?

回答

1

添加UINavigationController的範疇用下面的方法在您的項目

#import "UINavigationController+MyNavigation.h" 

@implementation UINavigationController (MyNavigation) 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

這解決了我的問題。

+0

它不能解決我的問題。我的視圖仍然可以在橫向和縱向模式下旋轉 –

+0

我對shouldAutorotateToInterfaceOrientation方法發表了評論。 –

+0

您的意思是評論shouldAutoRotate解決了您的問題? – Rajesh

相關問題