当XCODE到5以后,系统到ios7以后,UIViewController 的显示是占满全屏的,如果你以CGRectMake(0,0,50,50);这样的方式来添加一个空间那样的话,该控件会在信号栏上显示,(这样的控件放到ios7之前显示正常)如何解决这样的问题。如下
1:当该UIViewController没有在UINavigationController中的情况下需要来判断系统版本,如果是7以及以上的系统,Y起点在20像素后
判断语句#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0)? (YES):(NO))
if (IOS_VERSION_7_OR_ABOVE) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height-20)];
}else{
UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
}
2:当该UIViewController在UINavigationController中,需要从写系统中的界面布局格式,让布局格式在导航栏下开始,在viewDidLoad中添加下面一句
if ([[[UIDevicecurrentDevice] systemVersion]doubleValue]>=7.0) {
// 为了让视图从导航条下面开始进行
self.edgesForExtendedLayout =UIRectEdgeNone;
}
注意:
iOS7以上系统,self.navigationController.navigationBar.translucent默认为YES,self.view.frame.origin.y从0开始(屏幕最上部)。
此时若是添加代码self.edgesForExtendedLayout = UIRectEdgeNone(iOS7.0以后方法);self.view.frame.origin.y会下移64像素至navBar下方开始。但是此时当push到一个新的controller之前给当前屏幕截图的时候[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];,由于navBar是透明的,会出现64像素的黑色区域。
此时只需要把self.navigationController.navigationBar.translucent=NO即可,不需要加代码self.edgesForExtendedLayout;
iOS7之后也增加了一个self.tabBarController.tabBar.translucent的属性,默认为YES。当应用同时使用navBar和TabBar的时候。设置self.tabBarController.tabBar.translucent=NO并且self.navigationController.navigationBar.translucent=NO时候,得到self.view.frame--->{{0, 64}, {320, 455}}。视图的高度也改变为navBar和tabBar之间的455像素。当self.navigationController.navigationBar.translucent=YES并且self.tabBarController.tabBar.translucent=NO的时候self.view.frame--->{{0, 0}, {320, 519}};其都为YES的时候self.view.frame--->{{0, 0}, {320, 568}};
注意:设置self.edgesForExtendedLayout = UIRectEdgeNone;的时候会使得navBar和tabBar都不占空间。self.view.frame--->{{0, 64}, {320, 455}}。此时iOS7默认navBar和tabBar都是透明的。截图的时候需要注意。
iOS6以下系统,默认navBar和tabBar都不占空间。