Xcode5与iOS7的兼容性修改 (持续更新)
---------------------------------------------------------------------------
---------------------------------------------------------------------------
navigationController 在iOS7 上覆盖view的解决方法
在viewDidLoad里加入如下代码:
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
---------------------------------------------------------------------------
在编译时判断编译环境的代码(注意:这里是编译环境的判断,就是指xcode的版本号,不是运行时环境,不能混淆。举个例子,用xcode5编译后的二进制文件中不会出现指定给4.6编译的代码片段)
#if 70000 <= __IPHONE_OS_VERSION_MAX_ALLOWED
NSLog(@"----------------------Xcode 5 compile");
#else
NSLog(@"----------------------Xcode 4.6 compile");
#endif
如果是以xcode4.6为判断标准 70000应改为60000
---------------------------------------------------------------------------
Cell的适配
删除 restoration identify 即可解决 restoration identifier is not available on ios versions prior to 6.0 的警告
---------------------------------------------------------------------------
修改status Bar的方案
1. 由于现在的navigationBar和statusBar是连在一起的,切图时要请美工mm切两套图,一套高44pix,一套高64pix,在navigation设置背景时用
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {}
分别放置,否则会在ios6上出现navigationBar下沉的情况
2. 在plist文件中不要做任何修改。view controller-based status bar appearance这个属性不需要在plist文件中添加(因为这个属性只在ios7中起作用,默认是no),同时,status bar style属性不要删除,这个属性在ios7中失效,但是需要给ios6使用。
3. 如果viewcontroller都集成自底层父类,需要在父类里改写毁掉函数:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
并且在viewDidLoad里加入
if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
[self setNeedsStatusBarAppearanceUpdate];
}
这样就可以把statusBar字体改成白色(如果是黑色,返回UIStatusBarStyleDefault)
特别需要注意的是,页面初始化时,需要改写对应的viewController,比如,如果rootViewController使用tabBarController,但是tabBarController中又使用了NavigationController,那么需要重新集成NavigationController并且使用上述方法,而不能对UIViewController添加category.
---------------------------------------------------------------------------
label在iOS7中会变扁变宽,navigationItem会往中间挤
---------------------------------------------------------------------------