iOS11、iPhone X、Xcode9 适配

来源:互联网 发布:五金店软件 编辑:程序博客网 时间:2024/05/16 12:17

一、单纯升级iOS11后造成的变化

1. 升级后,发现某个拥有tableView的界面错乱,组间距和contentInset错乱,因为iOS11中 UIViewController 的 automaticallyAdjustsScrollViewInsets 属性被废弃了,因此当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;

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

 ([UIDevice currentDevice].systemVersion.floatValue >= 11.0) {    make.edges.equalTo(self.view.safeAreaInsets);} else {    make.edges.equalTo(self.view);}

iOS 11适配之跳转App Store评论
在iOS 11之前,为了让用户直接跳到App Store的评论页面,你的代码大概是这样写的:

-(void)goToAppStore{NSString *itunesurl = @"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=XXXXXXXX&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8";[[UIApplication sharedApplication] openURL:[NSURL URLWithString:itunesurl]];}

但是今天QA给我提了个bug,说是这个已经在iOS 11上不灵了,直接提示“无法连接App Store”!

我试了一下,果然如此,顺便看了一下其他家的APP,不少大厂的APP也掉进了这个坑里还没爬出来,比如饿了么,百度外卖等。经过搜索引擎的帮助,我找到了如下办法:

-(void)goToAppStore{NSString *itunesurl = @"itms-apps://itunes.apple.com/cn/app/idXXXXXX?mt=8&action=write-review";[[UIApplication sharedApplication] openURL:[NSURL URLWithString:itunesurl]];}

注意:把里面的XXX替换成你自己的APP ID。
转载地址:http://www.cocoachina.com/ios/20171011/20737.html