iOS 到7.0,很多机制及api都发生一些很重要的变化,下面谈一下自己发现的几点改变及解决方案
1,状态栏问题
关于状态栏透明,导航遮住状态栏问题,最主要的原因是因为导航是透明的话,会导致view上面的所有控件都上移,就会出现遮住的问题。在ios7.0中导航会自身为44或64身高,所以最主要的就是设置导航不透明就OK了
(1),最广泛的解决方案
第一步Info.plist中加入View controller-based status bar appearance
值设置为NO
第二步在AppDelegate 中加入以下代码
if ([[[UIDevice
currentDevice] systemVersion] floatValue] >= 7)
{
self.window.frame =
CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
UIApplication *myApp = [UIApplication
sharedApplication];
[myApp setStatusBarStyle:
UIStatusBarStyleLightContent];
}
但这种解决方案在我的工程中有个问题,我的工程有tabbar控制器,使用这种解决方案的话
(2)#define
IOS7_OR_LATER
(
[[[UIDevice currentDevice] systemVersion]
compare:@"7.0"] != NSOrderedAscending
)
if ( IOS7_OR_LATER )
{//7.0 以后
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.modalPresentationCapturesStatusBarAppearance = NO;
}
(3)self.navigationController.navigationBar.translucent=NO;
注:(2)和(3)方法只适合项目使用系统的导航栏的
(4)通过重载UIViewController的子类方法
在每个页面控制状态栏的显示或隐藏
-
(UIStatusBarStyle)preferredStatusBarStyle
{
return
UIStatusBarStyleLightContent;
}
//
-
(BOOL)prefersStatusBarHidden//for iOS7.0
{
return
NO;
}
2,tabbar问题
在7.0中,tabbar控制器的tabbar的子类少了,需要重载tabbar的请注意
3,7.0中更新了废弃了很多API,这里就不一一介绍了