2015-05-19 26 views
0

我有2個視圖控制器:ViewControllerA和ViewCotrollerB。如何確定視圖控制器的界面方向?

ViewControllerA只支持橫向左/右。

這些都是一些方法ViewControllerA.m:

ViewControllerB *control = [[ViewControllerB alloc] init]; 
[self presentViewController:control animated:NO completion:nil]; 

ViewControllerB支持全方向:

- (BOOL)shouldAutorotate{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
    return UIInterfaceOrientationLandscapeRight; 
} 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 

    [self settingLayoutForOrient:[[UIApplication sharedApplication] statusBarOrientation]]; 

} 

ViewControllerB當ViewControllerA呼叫跟蹤代碼顯示。

這些都是一些方法ViewControllerB.m:

- (BOOL)shouldAutorotate{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskAll; 
} 

- (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation{ 

[self settingLayoutForOrient:[[UIApplication sharedApplication] statusBarOrientation]]; 

} 

請幫我在下面回答問題:

  1. 從ViewControllerA和設備在人像模式,去ViewControllerB。爲什麼在第一次ViewControllerB apprear時,狀態的方向總是左右/左右,儘管設備處於縱向模式?

2.如何在ViewControllerB中第一次出現ViewControllerB時,在每種情況下(縱向,縱向,下方,面朝上,朝下,橫向向左,橫向向右)輕鬆實現狀態欄的朝向?

感謝您的幫助。

回答

0

如果您正在使用故事板,您可以按照以下步驟操作。

正如你所說,你需要viewcontrllerA在橫向左右只有viewcontrollerB在所有方向。

爲此,您可以遵循以下步驟

首先創建一個類的UINavigationController的。將其命名爲LandscapeNavigationController

創建另一個類的UINavigationController。將其命名爲FullNavigationController

現在在LandscapeNavigationController.m文件中寫下面的代碼。

- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

現在在FullNavigationController.m文件中寫下面的代碼。

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; 
} 

現在嵌入與NavigationController您ViewControllerA這將有類LandscapeNavigationController和ViewControllerB與NavigationController這將有類fullNavigationController。

現在將您的初始視圖控制器設置爲您的NavigationController之一併運行您的程序。

+0

嗨Paras vora,我不使用故事板,也不使用UINavigationController。 – Khoi

相關問題