Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

ios - Container View getting pushed down as if it had a UINavigationBar?

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

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;

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?

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.

When translucent = YES

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

when translucent = NO

+---------------------------------+
|                                 |
|     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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...