状态栏下没有导航栏的情况下扩展UIViewController的

状态栏下没有导航栏的情况下扩展UIViewController的

本文介绍了在状态栏下没有导航栏的情况下扩展UIViewController的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图没有导航栏,但我想在状态栏下显示内容。我检查了顶部条形下的延伸边缘,在我的视图控制器中的不透明条形图下,我想在状态栏下显示的视图对顶部布局指南有0垂直间距约束,但是,这仍然是我得到的:

My view does not have a navigation bar, but I want to display content under status bar. I've checked extend edges under top bars, under opaque bars in my view controller, the view that I want to display under status bar has 0 vertical spacing constraint to top layout guide, but still, here is what I get:

状态栏有20px纯白色背景,我不想要。我希望我的视图在状态栏下重叠,就像下面的模型一样:

The status bar has 20px solid white background, which I don't want. I want my view to overlap under status bar, just like the mockup below:

如何做到这一点,没有有一个可见的导航栏(我还有它)因为我的视图保证在导航控制器中,但它永远不会显示,因为我有很多自定义设计的部分,包括顶部条形图)?

How can I do that, without having a visible navigation bar (I still have it as my view is guaranteed to be inside a navigation controller, but it's will never be visible as I have a lot of custom designed sections including top bars)?

推荐答案

经过数小时的调查几个小时后,我找到了答案:

After investigating tens of pages for hours, I've found an answer:

for (NSLayoutConstraint *constraint in self.view.constraints) {
    if((constraint.firstItem == self.topLayoutGuide && constraint.secondItem == self.view) ||
       (constraint.secondItem == self.topLayoutGuide && constraint.firstItem == self.view))         {
        constraint.constant = -20;
    }
}

对于任何想知道的人,我都没有使用特定的回答,但这个问题的衍生解决方案:。

For anyone wondering, I did not use a specific one answer, but a derived solution from this question: iOS7 - View under status bar - edgesForExtendedLayout not working.

这篇关于在状态栏下没有导航栏的情况下扩展UIViewController的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:43