
以下是设置导航控制器的代码:
- (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 UINavigationControllernav.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 fileAppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];[app.navController pushVIEwController: app.rootController animated:YES];//Now apply the offset trick to remove the status gapapp.navController.vIEw.frame = CGRectOffset(app.navController.vIEw.frame,-20.0);总结
以上是内存溢出为你收集整理的ios – UINavigationController在顶部有额外的状态栏差距全部内容,希望文章能够帮你解决ios – UINavigationController在顶部有额外的状态栏差距所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)