Container View getting pushed down as if it had a UINavigationBar?(Container View 好像有 UINavigationBar 一样被下推?)
问题描述
我有一个带有容器视图的 UIViewController.这个容器视图包含一个 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;
Container View 在自身顶部添加了一些空间,就好像它有自己的导航栏一样.每当我将半透明设置为 YES 时,视图都会正确显示所有内容.每当我将 translucent 设置为 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
并将其设置为隐藏,但没有任何效果.不知何故,包含的视图继承了父容器的属性?每当我将半透明设置为 NO
时,如何避免在包含的视图上创建这个额外的空间?
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.
当半透明 = YES
+---------------------------------+
| |
| UINavigationBar |
| |
+---------------------------------+
| |
| |
| |
| |
| |
| UITableViewController |
| in a Contained View |
| |
| |
| |
| |
| |
| |
+---------------------------------+
半透明时 = 否
+---------------------------------+
| |
| UINavigationBar |
| |
+---------------------------------+
| |
|blank space created on top of view
| |
+---------------------------------+
| |
| |
| |
| |
| |
| |
| UITableViewController |
| in a Contained View |
| |
+---------------------------------+
附:我的观点比这更复杂,我只是在简单化.
P.S. My View is more complex than this, I'm simplyfying.
推荐答案
你在这里缺少的是一个半透明的导航栏位于你的视图控制器的视图之上,而一个非半透明的导航栏向下推你的视图控制器的视图(有效地调整它的大小).
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.
这篇关于Container View 好像有 UINavigationBar 一样被下推?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Container View 好像有 UINavigationBar 一样被下推?
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01