为什么将我的UITabBar载入人像时下移20个像素? [英] Why is my UITabBar shifting down 20 pixels when loaded on portrait?

查看:57
本文介绍了为什么将我的UITabBar载入人像时下移20个像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这也可以使底部正确显示人像(但仅在启动应用程序时)在横向模式下)。

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

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

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

和肖像:

and portrait:

我试图产生与CNBC应用类似的效果,并显示 UITabBar 在视图顶部。在审查 Mihai Damian的问题后,我尝试自定义UITabBar。

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.

我只添加了几行代码:

-(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的框架时,它在横向模式下消失了:

When I try modifying the frame of the UITabBar, it disappears on landscape mode:

再次分别在横向和纵向模式下启动时,在纵向上出现的高度不同。

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

在横向模式下启动:

Initiated in landscape mode:

以纵向模式启动:

Initiated in portrait mode:

有人以前遇到过此问题吗?如果是这样,您是如何解决的?

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

在以纵向模式加载视图时,似乎只是添加了状态栏的20个像素,好像找不到了一样。状态栏,即使它在那儿也是如此,因此,它会在状态栏已存在的20个像素之上添加20个像素。

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.

推荐答案

我实际上是通过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.

这篇关于为什么将我的UITabBar载入人像时下移20个像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆