iOS   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UINavigationController在顶部有额外的状态栏差距大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我设置它时,这看起来很简单,但我无法解释为什么状态栏和导航栏之间存在差距.此外,包含的视图看起来可能正确对齐,而只是向下移动的导航栏.差距看起来像状态栏的大小,所以我期望与它有关系,但我不知道什么.

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

- (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文件的视图,我已经模拟了状态栏,导航栏和标签栏.

解决方法

问题的确是,导航控制器总是期望为状态栏留出空间,这是20像素的差距.我搜索了一段时间后才发现这个解决方案有效:
//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

我最初发现了一个答案,这是对导航栏的看法的偏移,但它没有奏效.当您对导航控制器的实际视图执行此操作时,它将起作用.

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

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

//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,-20.0);

大佬总结

以上是大佬教程为你收集整理的ios – UINavigationController在顶部有额外的状态栏差距全部内容,希望文章能够帮你解决ios – UINavigationController在顶部有额外的状态栏差距所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。