第一种,你的app使用自带的UINavgationController的导航栏
众所周知,iOS7的标题栏(statusbar)已经和视图重叠在一起,所以y坐标的值有所改变。从而导致原来的app头部坐标向上偏移,而不是显示在正确的位置。如果你的app使用了下面的特性如下:
那么恭喜你,你只需要在你的ViewController里面的ViewDidLoad里面加入下面这句话就可以完成了适配:
self.edgesForExtendedLayout = UIRectEdgeNone;
然后你的app导航栏和状态栏的位置就已经恢复正确了。
第二种:你没有用系统自带的导航栏而是自己贴视图(View)模拟成导航栏的样子:
这种情况你就需要在AppDelegate文件里加入下面的代码:
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); self.window.bounds = CGRectMake(0,0, self.window.frame.size.width, self.window.frame.size.height); [[NSUserDefaults standardUserDefaults] setFloat:self.window.frame.size.height forKey:@"windowHeight"]; }
如果你用到了pushViewController的方法,别忘记在目的视图的ViewDidAppear里面加入下面的代码:
-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear: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; } }