首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UINavigationController顶部有额外的状态栏间隙

UINavigationController顶部有额外的状态栏间隙
EN

Stack Overflow用户
提问于 2012-01-16 05:55:54
回答 7查看 13.2K关注 0票数 10

当我设置它时,这看起来很简单,但我无法解释为什么状态栏和导航栏之间存在这种差距。此外,所包含的视图看起来可能是正确对齐的,只是导航栏向下移动。差距看起来像状态栏的大小,所以我想这与它有关,但我不知道是什么。

下面是设置导航控制器的代码:

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];

    advancedVC = [[AdvancedSearchFormVC alloc] initWithNibName:@"AdvancedSearchForm" bundle:nil];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:advancedVC];
    nav.navigationBar.tintColor = [UIColor defaultNavBarTint];
    nav.navigationBar.topItem.title = NSLocalizedString(@"SearchTitle", nil);
    UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"SearchButton", nil) style:UIBarButtonItemStylePlain target:self action:@selector(refreshPropertyList:)];          
    nav.navigationBar.topItem.rightBarButtonItem = searchButton;

    self.view = nav.view;
}

rootViewController使用来自xib文件的视图,我在该文件中模拟了状态栏、导航栏和选项卡栏。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2012-01-16 14:29:15

已通过修复导航控制器的插入方式解决此问题。而不是将其插入到已经放到选项卡栏控制器上的视图中,而应该将导航定位控制器直接放到导航控制器上。

代码语言:javascript
复制
advancedSearchFormVC = [[AdvancedSearchFormVC alloc] initWithNibName:@"AdvancedSearchForm" bundle:nil];
UINavigationController *searchNavController = [[UINavigationController alloc] initWithRootViewController:advancedSearchFormVC];

这只是tabbar控制器上的一个控制器,同时替换了advancedSearchFormVC。然后,将这个导航控制器添加到放在that栏控制器上的控制器数组中。

很抱歉给你带来麻烦,但这是我可以直接看到而不是看到的问题之一。我应该早些时候看到这一点,因为我在way栏控制器上已经有了另一个导航控制器,并且它是以相同的方式设置的。

谢谢你的帮助。

票数 0
EN

Stack Overflow用户

发布于 2012-06-18 21:46:01

实际上,问题是导航控制器总是希望为状态栏留出空间,即20像素的间隙。我四处寻找了一段时间,最后找到了这个有效的解决方案:

代码语言:javascript
复制
//nav is assumed to be a subclass or instance of UINavigationController
nav.view.frame = CGRectOffset(nav.view.frame, 0.0, -20.0);
//you can then add the navigation's view as a subview to something else

我最初找到了一个解决方案,它对导航栏的视图进行了这种偏移,但它不起作用。当您对导航控制器的实际视图执行此操作时,它会起作用。

我使用这种技术将来自另一个nib的导航控制器添加到我的主nib的空视图中,这样我就可以将它作为子视图放置在主屏幕中的任何位置。通过使用空视图作为占位符,并在我的主笔尖上定位框架,我创建了一个单独的笔尖和类来管理导航,后者管理用于处理其屏幕的其他笔尖。通过这种方式,我可以解决经典的“如何在我的导航控制器上添加横幅、图像或自定义视图”的问题,而导航控制器具体来说是一个subview...in iOS 5。

值得一提的是,我使用app委托来存储和访问所有其他控制器,因此它们被一个持久化实例保留,我可以从任何类访问它。在所有控制器的应用程序代理和viewDidLoad Create实例中创建和合成一些属性。这样我就可以在以后的任何地方引用我的应用程序中使用的所有控制器,方法是添加:

代码语言:javascript
复制
//this shows how to store your navigation controllers in the app delegate
//assumes you've added 2 properties (UINavigationController*)"navController" and (UIViewController*)"rootController" in your app delegate
//...don't forget to add #import "AppDelegate.h" to the top of the file

AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[app.navController pushViewController: app.rootController animated:YES];
//now apply the offset trick to remove the status gap
app.navController.view.frame = CGRectOffset(app.navController.view.frame, 0.0, -20.0);
票数 11
EN

Stack Overflow用户

发布于 2012-06-08 05:17:23

我以前也遇到过同样的问题。我用来向UIViewController添加UINavigationBar的代码如下:

代码语言:javascript
复制
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:self];
[self.view  addSubview:nc.view];

解决方案:

用你的UIViewController的属性检查器选中“想要全屏”复选框。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8873695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档