为什么我的 UITabBar 在纵向加载时会下移 20 像素?

发布于 2024-10-17 15:43:50 字数 2484 浏览 4 评论 0原文

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

在此处输入图像描述

这也使底部正确显示纵向(但仅当应用程序以横向模式启动时) 。 在此处输入图像描述

如果我以纵向方式启动应用程序,则横向和横向状态栏的高度似乎都会向下移动: 在此处输入图像描述

和肖像: 在此处输入图像描述

我正在尝试实现与 CNBC 应用类似的效果并显示 UITabBar 在视图的顶部。在查看 Mihai Damian 的问题后,我尝试自定义 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 像素对于状态栏。

I am loading a UITabBarController inside a UINavigationController. By default the UITabBar for the UITabBarController places it at the bottom of the view. By using the default option the bar is displayed correctly at the bottom position when the app is initiated on landscape.

enter image description here

This also makes portrait display correctly at the bottom, (but only when the app is initiated in landscape mode).
enter image description here

If I start the app on portrait, it appears to shift downwards the height of the status bar on both landscape:
enter image description here

and portrait:
enter image description here

I am trying to have a similar effect as the CNBC app and display the UITabBar at the top of the view. After reviewing Mihai Damian's question I attempted to customize the UITabBar.

I simply added a couple of lines of code:

-(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];
}

When I try modifying the frame of the UITabBar, it disappears on landscape mode:
enter image description here

and appears at different height on portrait when it again initiated in landscape and portrait respectively.

Initiated in landscape mode:
enter image description here

Initiated in portrait mode:
enter image description here

Has anyone encountered this problem before? If so, how did you go by solving it? Any help here would be greatly appreciated.

It just seems to add the 20 pixels of the status bar when the view is loaded on portrait mode, as if it was not finding the status bar even though it is there, hence, it adds 20 pixels on top of the already existing 20 pixels for the status bar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春花秋月 2024-10-24 15:43:50

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

I actually fixed this through IB. The view controller for some reason wants to add a status bar, all you have to do is set that up to none on IB, and check resize view to fit. Also, make sure the dimensions of your view are set to 768 x 1024.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文