在iOS 7中,UIStatusBar被设计成这样,它与视图合并:

(GUI由Tina tavvar设计)

It is cool, but it will somewhat mess up your view when you have something at the top part of your view, and it becomes overlapped with the status bar. Is there a simple solution (such as setting a property in info.plist) that can change the way it works [not overlapping] back to how it is in iOS6? I know a more straightforward solution is to have self.view.center.x + 20 points for every single view controller, but changing them will screw other dimensions up (having a different self.view.center.x can cause problem to custom segues, etc.) and suddenly it turns into a tedious job that is best to be avoided. I'll really be glad if someone can provide me an one-liner solution for this.

附注:我知道我可以隐藏状态栏

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

在didFinishLaunchingWithOptions方法中,但这是一个变通方法,一个避免问题的快捷方式,所以我不认为这是一个真正的解决方案。


当前回答

2013年9月19日更新: 固定缩放bug添加 self.window.bounds = CGRectMake(0,20, self.window.frame.size.width, self.window.frame.size.height); 纠正了NSNotificationCenter语句中的错别字

2013年9月12日更新: 修正了UIViewControllerBasedStatusBarAppearance为NO 增加了一个解决方案的应用程序与屏幕旋转 增加了一个改变状态栏背景颜色的方法。

显然,没有办法将iOS7的状态栏恢复到iOS6的工作状态。

然而,我们总是可以写一些代码,把状态栏变成像ios6一样,这是我能想到的最短的方法:

Set UIViewControllerBasedStatusBarAppearance to NO in info.plist (To opt out of having view controllers adjust the status bar style so that we can set the status bar style by using the UIApplicationstatusBarStyle method.) In AppDelegate's application:didFinishLaunchingWithOptions, call if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) { [application setStatusBarStyle:UIStatusBarStyleLightContent]; self.window.clipsToBounds =YES; self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20); //Added on 19th Sep 2013 self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height); } return YES;

为了:

检查是否是iOS 7。 设置状态栏的内容为白色,而不是UIStatusBarStyleDefault。 避免那些超出可见边界的子视图出现(对于从顶部进入主视图的动画视图)。 通过移动和调整应用程序的窗口框架,创造一种状态栏占用空间的错觉,就像在iOS 6中一样。

对于具有屏幕旋转功能的应用程序,

使用NSNotificationCenter通过添加来检测方向变化

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidChangeStatusBarOrientation:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];

在if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1),并在AppDelegate中创建一个新方法:

- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{
    int a = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue];
    int w = [[UIScreen mainScreen] bounds].size.width;
    int h = [[UIScreen mainScreen] bounds].size.height;
    switch(a){
        case 4:
            self.window.frame =  CGRectMake(0,20,w,h);
            break;
        case 3:
            self.window.frame =  CGRectMake(-20,0,w-20,h+20);
            break;
        case 2:
            self.window.frame =  CGRectMake(0,-20,w,h);
            break;
        case 1:
           self.window.frame =  CGRectMake(20,0,w-20,h+20);
    }
}

因此,当方向改变时,它将触发一个switch语句来检测应用程序的屏幕方向(纵向,倒置,横向左,或横向右),并分别改变应用程序的窗口框架,以创建iOS 6状态栏错觉。

更改状态栏的背景颜色:

Add

 @property (retain, nonatomic) UIWindow *background;

在AppDelegate.h中使背景成为类中的一个属性,并防止ARC释放它。(如果你不使用ARC,你不必这样做。)

之后,你只需要在if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)中创建UIWindow:

background = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, self.window.frame.size.width, 20)];
background.backgroundColor =[UIColor redColor];
[background setHidden:NO];

别忘了@synthesize background;@implementation AppDelegate!

其他回答

我要迟到了,但我只是想分享我所做的,基本上 最简单的解决方案

首先->转到你的信息。plist文件并添加状态栏样式->透明黑色样式(Alpha 0.5)

现在,它开始了:-

在你的AppDelegate.m中添加这段代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
     //Whatever your code goes here
  if(kDeviceiPad){

     //adding status bar for IOS7 ipad
         if (IS_IOS7) {
              UIView *addStatusBar = [[UIView alloc] init];
              addStatusBar.frame = CGRectMake(0, 0, 1024, 20);
              addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //change this to match your navigation bar
              [self.window.rootViewController.view addSubview:addStatusBar];
                    }
                }
    else{

         //adding status bar for IOS7 iphone
        if (IS_IOS7) {
            UIView *addStatusBar = [[UIView alloc] init];
            addStatusBar.frame = CGRectMake(0, 0, 320, 20);
            addStatusBar.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; //You can give your own color pattern
            [self.window.rootViewController.view addSubview:addStatusBar];
        }

    return YES;
   }

解决方案:

通过重写方法在你的视图控制器或rootviewcontroller中设置它:

-(BOOL) prefersStatusBarHidden
    {
        return YES;
    }

对于Archy Holt的回答,有一个小的选择,更简单一点:

a.在info.plist中设置“UIViewControllerBasedStatusBarAppearance”为“NO”

b.在AppDelegate的应用程序didFinishLaunchingWithOptions:中调用:

if ([[UIDevice currentDevice].systemVersion floatValue] < 7)
{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
}
else
{
    // handling statusBar (iOS7)
    application.statusBarStyle = UIStatusBarStyleLightContent;
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    self.window.clipsToBounds = YES;

    // handling screen rotations for statusBar (iOS7)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}

并添加方法:

- (void)applicationDidChangeStatusBarOrientationNotification:(NSNotification *)notification
{
    // handling statusBar (iOS7)
    self.window.frame = [UIScreen mainScreen].applicationFrame;
}

你也可以考虑子类化UIWindow来处理UIApplicationDidChangeStatusBarOrientationNotification本身。

最简单的方法就是在最新的Xcode上安装一个旧的SDK。

如何安装旧SDK到最新的Xcode?

你可以从http://www.4shared.com/zip/NlPgsxz6/iPhoneOS61sdk.html获取iOS 6.1 SDK,也可以下载旧的Xcode并从其内容中获取SDK 解压并粘贴到/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/ sdk 重新启动xcode。 你现在可以在项目的构建设置中选择一个旧的SDK

希望对你有所帮助。这对我有用=)

我发现这里是这个导航栏问题在iOS7的最佳替代方案和解决方案!!

http://www.appcoda.com/customize-navigation-status-bar-ios-7/

我希望它能消除我们所有的疑问和担忧。