【问题标题】:iPhone - Alternate Landscape View issueiPhone - 备用横向视图问题
【发布时间】:2011-06-25 12:59:27
【问题描述】:

我遇到了横向模式问题,我找不到出路。基本上,我有一个标签栏应用程序,在第一个标签中我有导航控制器。在此导航控制器中,第一个视图包含带有项目的表格,单击项目后,将推送描述该项目的详细视图。

我需要为列表视图和详细视图实现横向模式,但对于列表视图,我需要为横向模式使用不同的视图控制器(通常,类似于封面流)。细节视图只是改变方向,在这种情况下不需要使用备用视图控制器。

根据 Apple 的 Alternate Views 示例,我尝试通过为列表视图控制器实现模式视图控制器来实现此行为。当我在列表视图中时,这工作正常(当我将设备变为横向模式时,封面流视图控制器正确呈现)。当我显示详细视图时出现问题。当我更改设备方向时,封面流再次出现。我所期望的是,仅当列表视图出现在屏幕上时才会显示封面流。无论 NC 堆栈中当前有什么 VC,模态视图控制器似乎总是可见的。

在我看来,将模态 VC 呈现为特定 VC 的横向视图不适用于多个导航级别。

我还尝试将横向视图作为子视图添加到视图控制器视图中。使用此解决方案时,我对导航级别没有任何问题,但这里的问题是标签栏在横向模式下没有隐藏。我需要为封面流隐藏标签栏,这是通过呈现模态VC来实现的。

我将不胜感激有关此问题的任何帮助。

非常感谢!

【问题讨论】:

    标签: iphone modal-dialog landscape alternate


    【解决方案1】:

    在细节视图控制器中,您可以完全使用类似这样的东西来设置不同的视图(代码来自我最近的一个项目):

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation 
                                    duration:(NSTimeInterval)duration
    {
        if ([graphView superview]) {
            if (toOrientation == UIInterfaceOrientationPortrait ||
                toOrientation == UIInterfaceOrientationPortraitUpsideDown) {
                [graphView removeFromSuperview];
            }
        } else {
            if (toOrientation == UIInterfaceOrientationLandscapeLeft ||
                toOrientation == UIInterfaceOrientationLandscapeRight) {
                [[self view] endEditing:YES];
                [[self view] addSubview:graphView];
            }       
        }
    }
    

    现在在横向时隐藏标签栏(有点小技巧,但可以):

    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
    { 
        UIInterfaceOrientation toOrientation = self.interfaceOrientation;
    
        if ( self.tabBarController.view.subviews.count >= 2 )
        {
            UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
            UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];
    
            if(toOrientation == UIInterfaceOrientationLandscapeLeft ||
               toOrientation == UIInterfaceOrientationLandscapeRight) {                                     
                transView.frame = CGRectMake(0, 0, 480, 320 );
                tabBar.hidden = TRUE;
            }
            else
            {                               
                transView.frame = CGRectMake(0, 0, 320, 480);         
                tabBar.hidden = FALSE;
            }
        }
    }
    

    对于这个项目,我添加了一个名为“graphView”的视图,当且仅当在横向模式下我想显示它,然后我想隐藏标签栏。我认为这听起来与您所追求的相似。

    我预见的唯一潜在问题是,如果您在详细视图被推送之前进入横向模式,事情可能会变得不稳定。因此,您可能希望在列表视图控制器中使用这些方法。这个特殊的问题对我来说从来没有出现过,但这是我在意识到它没有实际意义之前就想到的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-12
      • 2011-07-01
      • 1970-01-01
      相关资源
      最近更新 更多