簡體   English   中英

在萬一的情況下如何確定視圖控制器的界面方向?

[英]How to determine interface orientation of view controller in case?

我有2個視圖控制器:ViewControllerA和ViewCotrollerB。

ViewControllerA僅支持左/右橫向。

這些是ViewControllerA.m中的一些方法:

- (BOOL)shouldAutorotate{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
     return UIInterfaceOrientationMaskLandscape;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
     return UIInterfaceOrientationLandscapeRight;
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

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

}

當ViewControllerA中的調用跟隨代碼時,將顯示ViewControllerB:

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

ViewControllerB支持完整方向。

這些是ViewControllerB.m中的一些方法:

- (BOOL)shouldAutorotate{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
     return UIInterfaceOrientationMaskAll;
}

- (void)didRotateFromInterfaceOrientation:  (UIInterfaceOrientation)fromInterfaceOrientation{

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

}

請幫助我回答以下問題:

  1. 在ViewControllerA和處於縱向模式的設備上,轉到ViewControllerB。 為什么在初次使用ViewControllerB時,盡管設備處於縱向模式,但狀態的方向始終是“橫向”向左/向右?

2.如何在首次出現ViewControllerB的情況下如何在ViewControllerB中的狀態欄(肖像,portraitUpsideDown,FaceUp,FaceDown,左風景,右風景)中獲得正確的方向?

謝謝你的幫助。

如果您使用情節提要,則可以執行以下步驟。

如您所說,您只需要在橫向左右中使用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;
}

現在,將帶有ViewControllerA的ViewControllerA嵌入到帶有LandscapeNavigationController的類中,將帶有ViewControllerB的ViewControllerB嵌入到帶有Navigationfull的類中的滿NavigationController的中。

現在,將初始視圖控制器設置為NavigationController之一,然后運行程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM