在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方法中,但这是一个变通方法,一个避免问题的快捷方式,所以我不认为这是一个真正的解决方案。


当前回答

最简单的方法就是在最新的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

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

其他回答

Interface Builder中有一个选项,调用iOS 6/7 Delta属性,旨在解决偏移问题。

在Stack Overflow的问题界面构建器:什么是UIView的布局iOS 6/7 delta ?

苹果发布了技术问答QA1797:防止状态栏覆盖你的视图。它适用于iOS 6和iOS 7版本。

我在iOS 7中实现了iOS 6的状态栏。

在info.plist中设置UIViewControllerBasedStatusBarAppearance为NO

(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    [application setStatusBarStyle:UIStatusBarStyleLightContent];
    self.window.clipsToBounds =YES;
    self.window.frame =  CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height);

    //Added on 19th Sep 2013
    NSLog(@"%f",self.window.frame.size.height);
    self.window.bounds = CGRectMake(0,0, self.window.frame.size.width, self.window.frame.size.height);
}

它可能会把你所有的视图都压低20个像素。要克服这一点,请使用以下代码在-(void)viewDidAppear:(BOOL)animated方法

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    CGRect frame=self.view.frame;
    if (frame.size.height==[[NSUserDefaults standardUserDefaults] floatForKey:@"windowHeight"])
    {
        frame.size.height-=20;
    }
    self.view.frame=frame;
}

你必须在didFinishLauncing Method中设置窗口分配后的windowHeight Userdefaults值

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[NSUserDefaults standardUserDefaults] setFloat:self.window.frame.size.height forKey:@"windowHeight"];

我在所有的视图控制器中都使用了这个,很简单。 在你所有的viewDidLoad方法中添加这行:

- (void)viewDidLoad{
    //add this 2 lines:
    if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout = UIRectEdgeNone;

    [super viewDidLoad];
}

如果你正在使用接口构建器,试试这个:

在你的xib文件中:

1)选择主视图,设置背景颜色为黑色(或任何你想要状态栏的颜色)

2) Make sure the background is a self contained subview positioned as a top level child of the controller's view. Move your background to become a direct child of the controller's view. Check the autosizing panel to be sure that you've locked all frame edges, activated both flexibility axes, and if this is a UIImageView, set the content mode to Scale to fill. Programmatically this translates to contentMode set to UIViewContentModeScaleToFill and has its auto resizing mask set to (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight).

3)现在将所有被锁定的东西上下移动20点,并设置iOS 6/7 delta Y为-20。 在自动缩放面板中,所有被锁定在顶部框架上的顶级子图层都需要向下移动20点,并将其iOS 6/7 delta Y设置为-20。(Cmd选择所有这些,并按下箭头20次-有更好的方法吗?)

4) Adjust the iOS 6/7 delta height of all of the above items that had a flexible height. Any of the items that were locked to the frame top and bottom and had flexible height enabled in the autosizing panel must also have their iOS 6/7 delta height set to 20. That includes the background view mentioned above. This may seem anti-intuitive, but due to the order in which these are applied, it is necessary. The frame height is set first (based on device), then the deltas are applied, and finally the autosizing masks are applied based upon the offset positions of all of the child frames - think it through for a bit, it will make sense.

5)最后,被锁定在底部框架而不是顶部框架的项目根本不需要delta。

这将给你在iOS7和iOS6中相同的状态栏。

另一方面,如果你想要iOS7样式同时保持iOS6兼容性,那么将背景视图的delta Y / delta height值设置为0。

要查看更多iOS7迁移信息,请阅读全文:http://uncompiled.blogspot.com/2013/09/legacy-compatible-offsets-in-ios7.html