为什么我的 UITabBar 在纵向加载时会下移 20 像素?
我正在 UINavigationController
中加载 UITabBarController
。默认情况下,UITabBarController
的 UITabBar
将其放置在视图的底部。通过使用默认选项,当应用程序在横向启动时,栏会正确显示在底部位置。
这也使底部正确显示纵向(但仅当应用程序以横向模式启动时) 。
如果我以纵向方式启动应用程序,则横向和横向状态栏的高度似乎都会向下移动:
和肖像:
我正在尝试实现与 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.
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:
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:
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上通过 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.