iOS 7导航栏隐藏内容 [英] iOS 7 Navigation Bar Hiding Content
问题描述
我有一个在iOS 6中开发的应用程序。但是现在在iOS 7甚至我的应用程序为iOS 6编译,但在iOS 7设备上运行顶部导航栏(iOS 7中的新巨人)我的内容是隐藏的。顶部导航栏覆盖它。如果我用CGRect手动移动它在iOS 7中看起来很好,但是现在iOS 6看起来很糟糕(在它上方的空间很大)。
I have an app that was developed in iOS 6. But now in iOS 7 or even my app compiled for iOS 6, but running on an iOS 7 device the top navigation bar (the new giant one in iOS 7) my content is hidden. The top navigation bar covers it. If I manually move it down with CGRect it looks good in iOS 7, but now iOS 6 looks horrible (to much space above it).
应用程序是在autolayout关闭的情况下构建的,因为自动布局是很难正确设置的方法。
The app was built with autolayout off because autolayout is way to difficult to get things setup correctly.
我的问题是,是否有一种简单的方法可以仅针对iOS 7移动内容?我真的不想重新开启autolayout并花一个月时间尝试将所有UI元素重新安装到位。该应用程序相当复杂,有30多个屏幕,屏幕上有很多动画视图。
My question is, is there an easy way to move the content down for iOS 7 only? I really don't want to have to turn autolayout back on and spend a month trying to get all the UI elements back in place. The app is pretty sophisticated with 30+ screens and a lot of animating view on screens.
推荐答案
我认为还有一点点即使iOS 7在一年多前推出,也存在误解这种布局问题的误解。所以我最终决定进一步阐述我的答案。
I think there's still a little bit of misconception going around this layout problem even if iOS 7 was rolled out more than a year ago. So I eventually decided to elaborate further my answer.
这就是事情。
因为 automaticAdjustsScrollViewInsets
'默认值为 YES
,一个非常简单的解决方案可能是添加以下代码:
Because automaticallyAdjustsScrollViewInsets
' default value is YES
, a pretty straightforward solution could be adding the following code:
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) { // if iOS 7
self.edgesForExtendedLayout = UIRectEdgeNone; //layout adjustements
}
进入ViewController的 -viewDidLoad
方法。
into the ViewController's -viewDidLoad
method.
如果您想删除状态栏怪癖(由于条形图半透明,所以它并不奇怪)添加 self.navigationController.navigationBar.translucent = NO
。默认值为 YES
。
注意:这与内容无关,因为半透明而与内容有关,但这是一个完全不同的故事!
If you wish to remove the status bar quirk (due to the bar translucency, so it's not weird whatsoever) add self.navigationController.navigationBar.translucent = NO
. The default value is YES
.
Note: this has nothing to do with the content, it's related to the content because of translucency but that's an altogether different story!
因为 extendedLayoutIncludesOpaqueBars
默认为否
, self.navigationController.navigationBar.translucent = NO
表示基本上有
Because extendedLayoutIncludesOpaqueBars
is NO
by default, self.navigationController.navigationBar.translucent = NO
means basically having
self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeRight| UIRectEdgeBottom;
或者,更一般地说,类似的东西(就像伪代码一样......)
Or, more generally, something like that (it's like pseudocode to give an idea...)
BOOL enableTopEdge = extendedLayoutIncludesOpaqueBars && !navigationBarIsTranslucent
self.edgesForExtendedLayout = (enableTopEdge & UIRectEdgeTop) | UIRectEdgeLeft | UIRectEdgeRight | UIRectEdgeBottom;
这篇关于iOS 7导航栏隐藏内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!