容器视图被推下来好像它有一个UINavigationBar? [英] Container View getting pushed down as if it had a UINavigationBar?

查看:93
本文介绍了容器视图被推下来好像它有一个UINavigationBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带容器视图的UIViewController。这个Container View包含一个UITableViewController。

I have a UIViewController with a Container View. This Container View contains a UITableViewController.

UIViewController嵌入在UINavigationController中。
我通过改变色调颜色,条纹色调和标题文本属性来配置NavigationBar,但是当我尝试更改半透明时我遇到了问题。我通过删除所有其他自定义代码来挑出问题。
每当我在UIViewController的 -viewDidLoad 中执行此操作时:

The UIViewController is embedded in a UINavigationController. I configure the NavigationBar by changing the tint color, the bar tint color and the title text attributes, but when I try to change the translucency I have a problem. I've singled out the problem by removing all the other customization code. Whenever I do this in UIViewController's -viewDidLoad:


self。 navigationController.navigationBar.translucent = NO;

self.navigationController.navigationBar.translucent = NO;

容器视图在其自身顶部添加一些空间,就好像它有自己的导航栏一样。每当我将半透明设置为YES时,视图都会正确显示所有内容。只有当我将半透明设置为NO时,才会在包含的视图中发生这种情况。

the Container View adds some space on top of itself, as if it had it's own navigation bar. Whenever I set translucent to YES the view displays everything correctly. This only happens on a contained view whenever I set translucent to NO.

这里是否有我缺少的东西?

Is there something that I'm missing here?

我尝试在所包含的视图上将半透明设置为 YES ,并将其设置为隐藏,但没有任何效果。
不知何故,包含的视图是否继承了父容器的属性?
每当我将半透明度设置为时,如何避免在包含的视图上创建额外空间?

I tried setting the translucency to YES on the contained view and also setting it to hidden, but nothing worked. Is somehow, the contained view inheriting properties from the parent's container? How do I avoid this extra space created on the contained view whenever I set the translucency to NO?

我希望设置半透明度只会影响半透明度,但不会影响视图的位置。

I would expect that setting the translucency only affects the translucency, but not the position of the views.

当半透明=是

+---------------------------------+
|                                 |
|     UINavigationBar             |
|                                 |
+---------------------------------+
|                                 |
|                                 |
|                                 |
|                                 |
|                                 |
|    UITableViewController        |
|    in a Contained View          |
|                                 |
|                                 |
|                                 |
|                                 |
|                                 |
|                                 |
+---------------------------------+

当半透明=否

+---------------------------------+
|                                 |
|     UINavigationBar             |
|                                 |
+---------------------------------+
|                                 |
|blank space created on top of view
|                                 |
+---------------------------------+
|                                 |
|                                 |
|                                 |
|                                 |
|                                 |
|                                 |
|     UITableViewController       |
|     in a Contained View         |
|                                 |
+---------------------------------+

PS我的观点比这更复杂,我只是在做什么。

P.S. My View is more complex than this, I'm simplyfying.

推荐答案

你在这里缺少的是一个半透明的导航栏坐着在viewcontroller的视图之上,而非半透明的导航栏会向下推动视图控制器的视图(有效地调整它的大小)。

What you are missing here is that a translucent navigation bar sits on top of your viewcontroller's view, while a non-translucent navigation bar pushes down your view controller's view (effectively resizing it).

所以这里发生的是半透明导航栏,白色空间实际上隐藏在栏下方,而当栏不是半透明时,它被推下。

So what is happening here is that with a translucent navigation bar, that white space is actually hidden underneath the bar, while when the bar is not translucent it's "pushed down".

有很多方法可以去关于它,它主要取决于你是否使用自动布局。

There are a number of ways to go about it, and it mainly depends on whether you're using auto layout or not.

这篇关于容器视图被推下来好像它有一个UINavigationBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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