ViewController中的UINavigationController,视图顶部的间隙 [英] UINavigationController within ViewController, gap at top of view

查看:246
本文介绍了ViewController中的UINavigationController,视图顶部的间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款通用应用,我正试图在iPhone和iPad版本之间共享尽可能多的代码。我需要使用TabBarController作为我的根视图控制器,虽然我想在每个选项卡中使用SplitViewController,但SplitViewController的文档说它需要是根视图控制器。因此,考虑到所有这些 - 了解我正在尝试并排放置两个导航控制器,并且(大部分)复制SplitViewController的行为/布局。

I'm working on a universal app, and I'm trying to share as much code as possible between the iPhone and iPad versions. I need to use a TabBarController as my root view controller and though I'd like to use a SplitViewController in each of the tabs, SplitViewController's docs say it needs to be the root view controller. So, with all of that in mind - understand that I'm attempting to place two navigation controllers side-by-side and (mostly) replicate the behavior/layout of a SplitViewController.

除了视图的布局外,一切正常。当应用程序以纵向模式启动时,一切都会在设备方向改变时正常运行并调整大小/位置。

Everything works just fine, except for the layout of the views. When the app is started in portrait mode, everything functions and resizes/positions correctly when the device orientation changes.

如果应用程序以UIDeviceOrientationPortrait以外的任何方向启动,则视图显示20点差距/ margin在导航控制器上方。我试过在运行时调整帧没有完美的结果。将框架的origin.y调整为-20并将高度增加20会使视图与其父级的顶部齐平,但在底部留下20个点的间隙!

If the app is started in any orientation other than UIDeviceOrientationPortrait, the view displays with a 20 point gap/margin above the navigation controller. I've tried adjusting the frame at runtime with no perfect result. Adjusting the origin.y of the frame to -20 and increasing the height by 20 brings the view flush with the top of it's parent, but it leaves a 20 point gap at the bottom!

推荐答案

我在我的应用中通过隐藏然后在添加导航控制器视图后显示导航栏解决了这个问题。例如。

I solved this in my app by hiding then showing the navigation bar after adding the navigation controllers view. eg.

[parentView addSubview:navController.view];
[navController setNavigationBarHidden:YES];
[navController setNavigationBarHidden:NO];

这篇关于ViewController中的UINavigationController,视图顶部的间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆