视图隐藏在UINavigationBar iOS 7下面 [英] View got hidden below UINavigationBar iOS 7

查看:152
本文介绍了视图隐藏在UINavigationBar iOS 7下面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早些时候,我在我的项目中使用iOS 6.1。最近我已经切换到iOS 7.对于我所知道的很多变化,我更新了我的代码..但我发现了一个奇怪的行为。我在每个屏幕上的视图都隐藏在导航栏下方。重新定位视图解决了iOS7的问题,但是为旧的iOS版本带来了问题。

Earlier, I was using iOS 6.1 for my project. Recently I have switched to iOS 7. For, a lot of changes I knew, I updated my code.. But I have observed a strange behavior. My view on every screen gets hidden below navigation bar. Repositioning view solves the problem for iOS7, but creates problems for older iOS versions.

任何人都可以解释一下,原因是什么?为什么会发生?在iOS 7中发生了什么变化导致了这个问题?

Can anyone explain me, what is the reason and why does it happen?? What has been changed in iOS 7 that's causing this problem??

任何帮助都将受到赞赏..

Any help would be appreciated..

推荐答案

尝试 navigationBar.translucent = NO; ,默认情况下 YES iOS7。

Try navigationBar.translucent = NO;, It is YES by default in iOS7.

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

It is also good to take a look on this part of UINavigationBar documentation:


iOS 7上的新行为。默认为YES。您可以通过将属性设置为NO来强制使用不透明的
背景。如果导航栏具有
自定义背景图像,则默认值是从图像的α值
推断出的,如果它具有alpha< 1.0如果您向具有不透明自定义背景图像的条形成发送
setTranslucent:YES,则
将对图像应用小于1.0的系统不透明度。如果你发送
setTranslucent:NO给一个带有半透明自定义背景图片的条形图
它将使用条形图的
barTintColor(如果已定义)为图像提供不透明背景,或者对于UIBarStyleBlack为白色为白色为白色为
如果barTintColor为零,则为UIBarStyleDefault。

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'值会导致异常。

Setting 'navigationBar.translucent' value causes exception if you run project in devices/simulators having older iOS versions.

因此您可以添加版本像这样检查:

So you can add a version check like this:

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

另一种选择是设置:

vc.edgesForExtendedLayout = UIRectEdgeNone;

Swift 3

vc.edgesForExtendedLayout = []

这篇关于视图隐藏在UINavigationBar iOS 7下面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆