iPhone:在UINavigationController的顶部空间怪异
-
22-07-2019 - |
题
我在与添加一个UINavigationController我的iPhone应用程序一个奇怪的问题。我添加所述控制器如下:
myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil];
myNavigationViewController *navigationController = [[myNavigationViewController alloc] initWithRootViewController:viewController];
UIView *finalView = myeNavigationViewController.view;
[self.view addSubview:finalView];
似乎一切按计划进行,除了我得到我的状态栏和UINavigationController的标题栏之间视图顶部一个奇怪的白色空间里工作。 替代文字http://www.andrewskinner.name/problem.png
我在网上搜索,但真的不知道该怎么寻找。有没有其他人有这个问题?你能指出我的一些帮助的方向是什么?
预先感谢。
解决方案
检查出答案在这样一个问题:
其他提示
什么行
UIView *finalView = myeNavigationViewController.view;
添加到代码?这是多余的,因为你可以在没有首先将其分配给一个UIView直接添加视图 - 再加上它是不正确的,它引用了myNavigationController而不是navigationController ..结果 我倾向于这样做
myViewController *viewController = [[myViewController alloc] initWithNibName:@"myView" bundle:nil];
myNavigationViewController *navigationController = [[myNavigationViewController alloc] initWithRootViewController:viewController];
[navigationController.view setFrame: [self.view bounds]];
navigationController.delegate = self;
[self.view addSubview:[navigationController view]];
的帧设置为边界还去除在你询问顶部的白色空间。
的问题是理想的UINavigationController应的UIWindow的直接子视图。它将定位和自身大小的权利。当添加的UINavigationController成一个UIWindow子视图的另一自定义视图,则需要通过考虑是否在一个UIWindow示出或不状态栏照顾该自定义视图的位置和大小的。
我的建议是使自定义视图的UINavigationController的子类:
mySubClass_NavigationController*nav=[[mySubClass_NavigationController alloc] initWithRootViewController:viewController ];
[myUIWindow addSubview:nav.view];
和mySubClass_NavigationController里面,你可以做一切你在你自己现在做的(无论是控制器)的定制。
我与此挣扎了同时使用太非常类似代码到运算的和也有我的上述导航控制装置的白条。
添加的UINavigationController如在UITabController的图时发生我的问题。在我的情况这个空间被的UINavigationController的考虑到状态栏,它实际上是重叠的,我是想在UINavigationController的显示视图的一部分的UINavigationBar的部分引起的。
这是在我的loadView结束了在我的UITabBarController视图控制器中的一个的代码。
SomeUITableViewController *screenList = [[SomeUITableViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:screenList];
CGRect frame = [[navController navigationBar] frame];
frame.origin.y = 0; // Was 20, set to 0 to not take into account the status bar.
[[navController navigationBar] setFrame:frame];
[self setView:[navController view]];
有在 http://discussions.apple.com/message.jspa一些更多的信息?MESSAGEID = 7890362 。
有在IB一个模糊属性称为“隐藏底酒吧上推”。只要检查一下。它解决了这个问题对我来说。
也许你已经在某种程度上得到了自己两个UIViews, 每一个状态栏。检查XIB。