【问题标题】:How to determine interface orientation of view controller in case?万一如何确定视图控制器的界面方向?
【发布时间】:2015-05-19 19:44:38
【问题描述】:

我有 2 个视图控制器:ViewControllerA 和 ViewCorollerB。

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第一次出现时,如何在每种情况下(portrait、portraitUpsideDown、FaceUp、FaceDown、横向左、横向右)获取状态栏的准确方向?

感谢您的帮助。

【问题讨论】:

    标签: ios orientation


    【解决方案1】:

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

    正如你所说,你只需要左右横向的 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 与 NavigationController 一起嵌入,NavigationController 将具有类 LandscapeNavigationController 和 ViewControllerB 与 NavigationController 将具有类 fullNavigationController。

    现在将您的初始视图控制器设置为您的 NavigationController 之一并运行您的程序。

    【讨论】:

    • 嗨 Paras vora,我不使用情节提要,也不使用 UINavigationController。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多