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

查看:21
本文介绍了视图隐藏在 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;,iOS7默认为YES.

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 值推断出来的图像的 - 如果它具有任何 alpha <的像素,则为 YES1.0 如果你发送setTranslucent:YES 对带有不透明自定义背景图像的栏将对图像应用小于 1.0 的系统不透明度.如果你发送setTranslucent:NO 带有半透明自定义背景图像的栏它将使用条形图为图像提供不透明的背景barTintColor 如果定义,或者 UIBarStyleBlack 为黑色,或者 UIBarStyleBlack 为白色UIBarStyleDefault 如果 barTintColor 为 nil.

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天全站免登陆