【问题标题】:Why is my UITabBar shifting down 20 pixels when loaded on portrait?为什么我的 UITabBar 在纵向加载时会向下移动 20 像素?
【发布时间】:2011-02-14 21:04:56
【问题描述】:

我正在将UITabBarController 加载到UINavigationController 中。默认情况下,UITabBarControllerUITabBar 将其放置在视图的底部。通过使用默认选项,当应用在横向上启动时,该栏会正确显示在底部位置。

这也使得纵向显示在底部正确,(但仅当应用程序以横向模式启动时)。

如果我在纵向上启动应用程序,它似乎会在两个横向上向下移动状态栏的高度:

和肖像:

我试图产生与 CNBC 应用程序类似的效果,并在视图顶部显示 UITabBar。在查看了Mihai Damian's question 之后,我尝试自定义 UITabBar。

我只是添加了几行代码:

-(void)loadView{
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor clearColor];
    self.view = contentView;
    [contentView release];

    orderingTabBarController = [[UITabBarController alloc] init];
    OrderingSpecialsViewController *specialsViewController = [[OrderingSpecialsViewController alloc] initWithNibName:@"OrderingSpecialsViewController" bundle:nil];
    OrderingProductViewTabBarController *productViewTabBarController = [[OrderingProductViewTabBarController alloc] init];
    OrderingSummaryViewController *summaryViewController = [[OrderingSummaryViewController alloc] init];

    specialsViewController.title = @"SPECIALS";
    productViewTabBarController.title = @"PRODUCT";
    summaryViewController.title = @"ORDER SUMMARY";

    [orderingTabBarController setViewControllers:[NSArray arrayWithObjects:specialsViewController, productViewTabBarController, summaryViewController, nil] animated:YES];
    orderingTabBarController.tabBar.frame = CGRectMake(0.0, 110.0, self.view.frame.size.width, 40.0);

    [specialsViewController release];
    [productViewTabBarController release];
    [summaryViewController release];

    [self.view addSubview:orderingTabBarController.view];
}

当我尝试修改 UITabBar 的框架时,它会在横向模式下消失:

当它再次分别以横向和纵向启动时,在纵向上出现在不同的高度。

以横向模式启动:

以纵向模式启动:

以前有人遇到过这个问题吗?如果是这样,您是如何解决的?在这里的任何帮助将不胜感激。

当视图以纵向模式加载时,它似乎只是添加了状态栏的 20 像素,就好像它没有找到状态栏,即使它在那里,因此,它在已经添加的顶部添加了 20 像素状态栏现有 20 像素。

【问题讨论】:

    标签: cocoa-touch ios uinavigationcontroller uitabbarcontroller uitabbar


    【解决方案1】:

    我实际上是通过 IB 解决了这个问题。视图控制器出于某种原因想要添加一个状态栏,您所要做的就是在 IB 上将其设置为无,并检查调整视图大小以适应。此外,请确保您的视图尺寸设置为 768 x 1024。

    【讨论】:

    • 当您的视图未在 IB 中构建时,有人知道如何执行此操作吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多