本文介绍了iOS 7 状态栏与 NavigationBar 冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我的应用程序中有一个视图控制器,它在故事板中拖动了一个导航栏.它在 iOS 6 中运行良好,但在 iOS 7 中它看起来像这样:

I have a view controller in my app that has a navigation bar dragged on it in the storyboard. It was working fine in the iOS 6 but in iOS 7 it look like this:

状态栏和导航栏不应相互碰撞.我在堆栈溢出上看到了很多这样的问题,但它们对我没有太大帮助.

The status bar and the navigation bar should no collide with each other. I have seen a lot of such questions on the stack overflow but they didn't of much help to me.

有些问题说我应该使用这个self.edgesForExtendedLayout = UIRectEdgeNone;"但它没有用.有人说我应该删除导航栏并将其嵌入到导航控制器中,但由于我的程序的实现方式,我无法做到这一点.一些解决方案建议使用视图边界,但它对我也不起作用.

Some questions say that i should use this "self.edgesForExtendedLayout = UIRectEdgeNone;" but it didn't work. Some say i should remove the navigation bar and embed it inside the navigation controller that i cannot do due to the way my program is implemented. Some solutions suggests to use the view bounds and all but it didn't work for me as well.

可以帮助我解决此问题的一件事是什么.提前致谢!

What is the one thing that can help me resolve this issue. Thanks in advance!

更新:我已将视图控制器嵌入到 uinavigation 控制器中.删除了之前手动添加的导航栏.现在它在故事板中看起来不错,但是当我运行它时,它显示以下内容:

UPDATE: I have embedded the view controller inside a uinavigation controller. Removed the navigation bar that was earlier manually added in it. Now it looks ok in the storyboard but when i run it, it shows the following:

它正在显示来自当前位于其父视图控制器后面的另一个视图控制器的文本.意味着它现在是透明的.谁能指出我做错了什么?

It is showing text from another view controller that is currently behind it that is its parent view controller. Means its transparent now. Can anyone point out what i am doing wrong?

推荐答案

最新版本的 iOS 带来了很多视觉上的变化,从开发者的角度来看,导航和状态栏是两个显着的变化.

The latest version of the iOS has brought many visual changes and from a developer's point of view, the navigation and status bar are two noticeable changes.

状态栏现在是透明的,它后面的导航栏显示出来.导航栏图像甚至可以扩展到状态栏后面.

The status bar is now transparent and navigation bar behind it shows through. The navigation bar image can even be extended behind the status bar.

首先,如果您是初学者并且刚刚开始 iOS 开发并且对状态栏和导航栏的工作方式感到困惑,您可以简单地阅读一篇博客文章 这里 我发现它非常有用.它具有 iOS 7 中与导航和状态栏相关的所有信息.

First of all, if you are a beginner and have just started iOS development and are confused the way status bar and navigation bar is working, you can simply go through a blog post HERE that i found very useful. It has all the information related to navigation and status bar in iOS 7.

现在来回答你的问题.首先,我可以看到两个不同的问题.一个是您的状态栏和导航栏都相互碰撞,如您在问题中用图像显示的那样.

Now coming to the answer of your question. First of all i can see two different problems. One is that your status bar and navigation bar are both kind of colliding with each other as shown by you in the question with an image.

问题:问题是您之前在视图控制器中拖动了一个导航栏,该导航栏在 iOS 6 中正常工作,但随着 iOS 7 SDK 的到来,这种方法导致状态栏和导航栏相互重叠.

PROBLEM: Well the problem is that your have earlier dragged a navigation bar in your view controller which was working in iOS 6 correctly but with the arrival of iOS 7 SDK, this approach is resulting in status bar and navigation bar overlapping with each other.

第一个问题的解决方案:您可以使用 UIBarPositionTopAttached 或使用视图边界和框架,我也可以建议您并将您链接到 Apple 的文档 和bla bla bla 但那你需要一些时间来解决这个问题.

SOLUTION to First Problem: You can either use UIBarPositionTopAttached or you can use view bounds and frames, i can also suggest and link you to Apple's documentation and bla bla bla but that would take some time for you to solve the issue.

解决这个问题的最好和最简单的方法就是将你的视图控制器嵌入到导航控制器中,就是这样.您只需选择视图控制器并转到 Editor > Embed In > Navigation Controller 即可完成此操作.(如果旧导航栏有内容,可以先将其向下拖动,将视图控制器嵌入到导航控制器中,然后移动新导航栏上的栏按钮,然后删除旧导航栏)

The best and the most easiest way to solve this issue is to just embed your view controller inside a navigation controller and thats it. You can do it by just selecting the view controller and going to Editor > Embed In > Navigation Controller. (If there is any content on your old navigation bar, you can first drag it down, embed the view controller in navigation controller and then move the bar buttons on the new navigation bar and then delete the old navigation bar)

第二个问题的解决方案:此解决方案适用于您在更新中提到的具体问题,不适合阅读本文的普通大众.如您所见,导航和状态栏不可见,并且透明区域显示父视图控制器.我并没有真正了解您为什么面临这个问题,但很可能是因为涉及到一些第三方库,如 ECSlidingView 或任何其他库.您可以在故事板中选择此视图控制器并将视图的背景颜色设置为与导航栏相同.这将停止显示后面的父视图控制器,您的导航栏和状态栏将开始显示.现在,您可以使用文本视图或您在其中使用的内容覆盖视图控制器的其余部分.

SOLUTION to Second Problem: This solution is for your specific question that you have mentioned in the update and is not for the general public reading this. As you can see that navigation and status bar is not visible and a transparent area is showing the parent view controller. I am not really use why you are facing this issue but most probably because of some third party library like ECSlidingView or any other is involved. You can select this view controller in your storyboard and set the background color of the view to be the same as your navigation bar. This will stop showing the parent view controller behind and your navigation bar and status bar will start showing. Now you can cover the rest of your view controller with text view or what ever your are using in it.

希望这有帮助!

这篇关于iOS 7 状态栏与 NavigationBar 冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:20