如何防止UINavigationBar覆盖iOS 7中的顶部视图?

问题描述:

更新到Xcode 5后,我所有应用视图中的导航栏都向下移动了。下面是一些截图,第一个显示视图中的所有内容,因为它被拉下来,第二个显示所有内容都未触及。搜索栏应从导航栏开始。

After updating to Xcode 5, the navigation bars in all of my app's views have shifted down. Here are some screenshots, the first showing everything in the view as it's pulled down, and the second showing all of it untouched. The search bar should begin where the navigation bar.


任何人都知道如何解决这个问题?

Anyone know how I can fix this?

编辑:我之前尝试过这个建议:

edit: i have tried this previously recommendation:

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

但它会产生非常奇怪的结果。

But it yields very odd results.

这可能是因为我在这个视图控制器下面有一个幻灯片菜单,由于导航栏的透明度而出现。

This may be because I have a "slide menu" under this view controller that is appearing due to the transparency of the navigation bar.

导航栏的半透明属性设置为NO

self.navigationController.navigationBar.translucent = NO;

这将修复视图在导航栏和状态栏下面的框架。

This will fix the view from being framed underneath the navigation bar and status bar.

如果您必须显示和隐藏导航栏,请使用

If you have to show and hide the navigation bar, then use

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;   // iOS 7 specific

viewDidLoad 方法。