1、baseline
- 崩溃信息:
'Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'
- 原因
因为偷懒使用了reset to suggested constraints, autolayout 帮我自动加了baseline的constraints,而baseline只有iOS8以后才有,兼容iOS7就崩溃了,直接移除baseline相关的constraint即可。 - 参考链接
http://stackoverflow.com/questions/26024906/unable-to-create-description-in-descriptionforlayoutattribute-layoutitem-coeffi/26045383#26045383
2、[[UINavigationBar appearance] setTranslucent:NO]
- 崩溃信息
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:'
- 原因
iOS8.0之后[UINavigationBar appearance]才可以setTranslucent,兼容iOS7需要添加判断
if(IOS8_OR_LATER && [UINavigationBar conformsToProtocol:@protocol(UIAppearanceContainer)]) {
[[UINavigationBar appearance] setTranslucent:NO];
}
3、storyboard segue show
-
异常现象
- 原因
在iOS7下如果没有设置navigationController为initController,show会自动将push转换成modal。简而言之就是在sb里每个show的segue,必须保证它的初始位置有个navigationController。 - 参考链接
http://stackoverflow.com/questions/25633739/could-not-instantiate-class-named-uistoryboardshowseguetemplate-how-can-i-ma
4、constrain to margin
-
异常现象
-
原因
这是设置了constrain to margins的关系,这玩意也是iOS8后才有的,把这个钩去掉,就OK了
5、 imageFromBundle
在iOS8下,下面这段代码是没有问题的。
+ (UIImage *)imagesNamed:(NSString *)name fromBundle:(NSString *)bundleName
{
NSString *main_images_dir_path = [[[NSBundle mainBundle] resourcePath] stringByAppendingFormat:@"/%@.bundle",bundleName];
NSString *image_path = [main_images_dir_path stringByAppendingPathComponent:name];
return [UIImage imageWithContentsOfFile:image_path];
}
而在iOS7下,返回的UIImage是nil。原因是在iOS7下,必须要加上.png
或者@2x.png
,否则[UIImage imageWithContentsOfFile:image_path]
是无法争取找到文件路径的。