美文网首页iOSiOS开发代码段程序员
【TIP】兼容iOS7的几个坑

【TIP】兼容iOS7的几个坑

作者: 千煌89 | 来源:发表于2014-12-24 09:25 被阅读3708次

1、baseline

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

  • 异常现象


    sb里segue使用show
    在iOS8下是正常push的
iOS7下变成从底部推出的,而且没有navigation

4、constrain to margin

  • 异常现象


    使用tableview顶部会出现不正常的空白
  • 原因
    这是设置了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]是无法争取找到文件路径的。

相关文章

网友评论

本文标题:【TIP】兼容iOS7的几个坑

本文链接:https://www.haomeiwen.com/subject/tzratttx.html