iphone - View 隐藏在 UINavigationBar iOS 7 下方

标签 iphone ios uiview ios7 navigationbar

之前,我的项目使用的是 iOS 6.1。最近我切换到 iOS 7。因为,我知道很多变化,我更新了我的代码。但是我观察到一个奇怪的行为。我在每个屏幕上的 View 都隐藏在导航栏下方。重新定位 View 解决了 iOS7 的问题,但为旧的 iOS 版本带来了问题。

谁能解释一下,这是什么原因,为什么会这样??导致此问题的 iOS 7 中发生了什么变化??

任何帮助将不胜感激..

最佳答案

试试navigationBar.translucent = NO;,iOS7默认是YES

看一下 UINavigationBar 文档的这一部分也很好:

New behavior on iOS 7. Default is YES. You may force an opaque background by setting the property to NO. If the navigation bar has a custom background image, the default is inferred from the alpha values of the image—YES if it has any pixel with alpha < 1.0 If you send setTranslucent:YES to a bar with an opaque custom background image it will apply a system opacity less than 1.0 to the image. If you send setTranslucent:NO to a bar with a translucent custom background image it will provide an opaque background for the image using the bar's barTintColor if defined, or black for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.

编辑:

如果您在具有较旧 iOS 版本的设备/模拟器中运行项目,则设置“navigationBar.translucent”值会导致异常。

所以你可以像这样添加一个版本检查:

float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
    navigationBar.translucent = NO;
}

另一种选择是设置:

vc.edgesForExtendedLayout = UIRectEdgeNone;

swift 3:

vc.edgesForExtendedLayout = []

关于iphone - View 隐藏在 UINavigationBar iOS 7 下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18824994/

相关文章:

iphone - 在 Objective-C 中复制 UI 元素

ios - 无法控制将按钮拖动到 SecondViewController 中

iphone - iOS 中的自定义形状(倒 T)边框 Uiview

iphone - 设置转换 :CGAffineTransformMakeScale - Alternatives when trying to scale an UIView

iphone - 是否可以减慢scrollRangeToVisible的速度?

iphone - 使用 CABasicAnimation 时,CALayer 未绘制其内容

iphone - 在排序的核心数据获取结果中排序?

ios - 我在所有模拟器的屏幕顶部和底部都有一个大黑条

ios - 通过 initWithRootViewController 以外的方法设置 UINavigationController 的 rootViewController

iphone - CATextlayer 中的行数?