1

到目前为止我还没有找到任何与我的情况相对应的东西......

仅供参考,我正在使用情节提要为 iOS 5 开发。

我有一个带有2 个视图的选项卡栏控制器(我们称它们为选项卡 1 和选项卡 2)。我还有一个单独的横向视图,没有标签栏,在应用程序使用期间设备旋转的任何时候都会使用它。我使用手动启动的 segue来切换到这个视图。我还在横向视图中使用 NSString 来了解我来自哪个选项卡,以便在我返回纵向时返回更正一个选项卡。到目前为止,这工作正常。我可以完全按照我想要的方式来回切换横向模式。shouldAutorotateToInterfaceOrientation

我的问题是:

当我以纵向方式启动应用程序时,我会看到标签栏。如果我去风景,它就会消失。这很好,这就是我在故事板中所做的。但是当我回到肖像时,标签栏没有回来!那就是问题所在。

编辑:调用旋转的代码

我停止使用shouldAutorotateToInterfaceOrientation旋转,因为它与自定义 segues 冲突。标签栏的问题以前就在这里,所以这不是问题。我didRotate改用。

这是来自FirstViewController.m(相同的代码SecondViewController.m,更改我的 segue 标识符)的代码:

-(void)didRotate:(NSNotification *)notification
{ 
    UIInterfaceOrientation newOrientation =  [[UIDevice currentDevice] orientation];
    if ((newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight)) 
    {
        [self performSegueWithIdentifier: @"Page1ToLandscapeSegue" sender: self];
    }
}

LandscapeViewController.mpreviousView是一个 NSString,在进入横向之前设置,所以我知道我来自哪个视图):

-(void)didRotate:(NSNotification *)notification
{ 
    UIInterfaceOrientation newOrientation =  [[UIDevice currentDevice] orientation];
    if (newOrientation == UIInterfaceOrientationPortrait)
    {
        if ([previousView isEqualToString: @"View1"]) {
            [self performSegueWithIdentifier: @"LandscapeToPage1Segue" 
                                      sender: self];
        }

        else if ([previousView isEqualToString: @"View2"]) {
            [self performSegueWithIdentifier: @"LandscapeToPage2Segue" 
                                      sender: self];
        }
    }
}
4

1 回答 1

3

查看您的评论,我认为您的标签栏正在消失,因为您正在从未嵌入标签栏控制器的视图控制器(这是您的横向视图视图控制器)中分离,我建议以下内容:

1) 设置 segues 以返回到前一个视图似乎很复杂,更不用说您正在创建更多视图/控制器并将它们添加到堆栈中,所以丢弃返回到原始视图的 segues。

2)使横向视图的segues成为模态的,这样当你segue到它们时你不会显示标签栏,如果你使用push它将嵌入标签栏控制器中。

3)由于景观视图将是一个模态视图,只需在景观视图控制器的旋转代码中调用此方法:

[[self presentingViewController] dismissModalViewControllerAnimated:YES];

这会将视图推离堆栈并返回到它来自的视图。

于 2012-09-03T15:52:51.960 回答