美文网首页
iOS11及xcode9的适配问题

iOS11及xcode9的适配问题

作者: QQWeb1234qwe | 来源:发表于2017-11-14 14:36 被阅读0次

    注: 本文内容选自http://www.jianshu.com/p/e97581110a59  仅供学习使用 

    1.升级iOS11后造成的变化

    1. 1升级后,发现某个拥有tableView的界面错乱,组间距和contentInset错乱,因为iOS11中UIViewControllerautomaticallyAdjustsScrollViewInsets属性被废弃了,因此当tableView超出安全区域时,系统自动会调整SafeAreaInsets值,进而影响adjustedContentInset

    // 有些界面以下使用代理方法来设置,发现并没有生效

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

    // 这样的原理是因为之前只是实现了高度的代理方法,却没有实现View的代理方法,iOS10及以前这么写是没问题的,iOS11开启了行高估算机制引起的bug,因此有以下几种解决方法:

    // 解决方法一:添加实现View的代理方法,只有实现下面两个方法,方法 (CGFloat)tableView: heightForFooterInSection: 才会生效

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    return nil;

    }

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    return nil;

    }

    // 解决方法二:直接使用tableView属性进行设置,修复该UI错乱

    self.tableView.sectionHeaderHeight = 0;

    self.tableView.sectionFooterHeight = 5;

    [_optionTableView setContentInset:UIEdgeInsetsMake(-35, 0, 0, 0)];

    // 解决方法三:添加以下代码关闭估算行高

    self.tableView.estimatedRowHeight = 0;

    self.tableView.estimatedSectionHeaderHeight = 0;

    self.tableView.estimatedSectionFooterHeight = 0;

    1.2 如果使用了Masonry 进行布局,就要适配safeArea

    if ([UIDevice currentDevice].systemVersion.floatValue >= 11.0) {

    make.edges.equalTo(self.view.safeAreaInsets);

    } else {

    make.edges.equalTo(self.view);

    }

    1.3 对于IM的发送原图功能,iOS11启动全新的HEIC 格式的图片,iPhone7以上设备+iOS11排出的live照片是".heic"格式图片,同一张live格式的图片,iOS10发送就没问题(转成了jpg),iOS11就不行

    微信的处理方式是一比一转化成jpg格式

    QQ和钉钉的处理方式是直接压缩,即使是原图也压缩为非原图

    微信的逼格太高,没找到现成的方法,我采用的是QQ 的方案

    相关文章

      网友评论

          本文标题:iOS11及xcode9的适配问题

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