代码之家  ›  专栏  ›  技术社区  ›  Jorge

UINavigationController中的UITableView在旋转后位于导航栏下

  •  3
  • Jorge  · 技术社区  · 15 年前

    这是一幅肖像画:

    alt text

    alt text

    我在轮换时尝试过,但没有成功:

    self.tableView.autoresizesSubviews = YES;
    self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    
    8 回复  |  直到 6 年前
        1
  •  13
  •   Sid    14 年前

    我最近遇到了这个问题。在我的例子中,这是因为我正在执行导航控制器的旋转,而导航控制器不是应用程序窗口的根控制器。因此,我使用旋转通知侦听器/仿射变换/边界调整方法来更改导航控制器的布局。这一切正常,但产生了这里描述的结果。我花了一段时间才注意到,当我旋转到横向时,导航栏的高度没有正确调整大小(即,从44像素到32像素,横向模式下框架的降低高度)。我的应用程序的根视图控制器 响应 willRotateToInterfaceOrientation 双旋转面间定向 willRotateToInterfaceOrientation

    CGRect frame = self.navViewController.navigationBar.frame;
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        frame.size.height = 44;
    } else {
        frame.size.height = 32;
    }
    self.navViewController.navigationBar.frame = frame;
    

    希望这能在类似情况下节省一些时间。

        2
  •  7
  •   Jack    13 年前

    当使用自定义视图控制器作为根控制器(它管理其他视图控制器本身)时,它负责将所有旋转事件转发到当前活动的子控制器(如果我可以这样称呼它的话)。这些活动包括:

    – willRotateToInterfaceOrientation:duration:
    
    – willAnimateRotationToInterfaceOrientation:duration:
    
    – didRotateFromInterfaceOrientation:
    
    – willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
    
    – didAnimateFirstHalfOfRotationToInterfaceOrientation:
    
    – willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
    

    因此,对于由自定义根控制器管理的导航控制器,转发 – willAnimateRotationToInterfaceOrientation:duration: 到导航控制器修复了旋转时导航栏高度错误的问题。

        3
  •  6
  •   chandu    13 年前

    在didRotateFromInterfaceOrientation方法中添加以下行。

    [self.navigationController.view布局子视图];

    我希望这样就可以了。

        4
  •  2
  •   marbleblue.co.uk    13 年前

    我有完全相同的问题,@jstevenco让我找到了一个非常奇怪的解决方案。 “我的视图”也会在旋转时自动调整大小,但tableview似乎不知道那里有一个navigationcontroller:

    在tableviewcontroller中,添加以下内容:

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
     CGRect frame = navBar.frame;
    if (fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        frame.size.height = 31.9;
    } else {
        frame.size.height = 44.1;
    }
    navBar.frame = frame;  
    
    }
    

    31.9和44.1非常重要!剩下的是32和44,不需要调整大小,所以它似乎忽略了它。为我工作,希望能帮助别人。

        5
  •  0
  •   Ben S    15 年前

    我觉得在方向改变后,表格视图会向下滚动一点。

    你打过电话吗 scrollToRowAtIndexPath:atScrollPosition:animated: 滚动到最上面一行?

        6
  •  0
  •   nzeltzer    15 年前

    你应该有这样的东西:

            - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
            [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation];
    // Your code here
    
        }
    
        7
  •  0
  •   delany    14 年前

    在这些情况下,需要注意的一点是,如果手动更改状态栏,则状态栏的方向。如果状态栏未隐藏,并且在状态栏的方向错误时更改了视图的框架(在代码中,可能是在框架更改后更新了状态栏的方向),则即使未启用“自动调整大小”,它也会错误地自动调整导航栏的大小。

        8
  •  0
  •   Andreas Ley Jonas    12 年前

    你的 UINavigationController view 属于 导航控制器 UIView .

    addChildViewController: 在父母身上 UIViewController