美文网首页
iOS11 及iPhone X适配

iOS11 及iPhone X适配

作者: BLUEVIPIOS_ | 来源:发表于2017-10-11 17:31 被阅读0次

          Xcode9升级很开心,运行项目app崩溃页面也跟预想的不太一样。要打脸了。接下来做下iOS11适配了。给大家总结一下本人踩的坑分享与大家。

    1.  Tableview. CollectionView类似的都是表

          UIScrollView以及子类frame整体下移问题,原因:在iOS 11中被弃用,取而代之的是UIScrollView的 contentInsetAdjustmentBehavior。导致整个页面布局错误。若项目中未使用automaticallyAdjustsScrollViewInsets属性,则无需适配你的页面也正常(相对而言)解决办法可以针对iOS 11用新API:

    if (@available(iOS 11,*)) {

    if ([tableview respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {

    tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

    }

    } 另一方面,iOS11 默认推荐系统自动估算行高方式,想关闭也行的采用这种方式:

    解决方法一 :添加实现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;

    加一框架  Masonry布局需要做下处理

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

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

    } else {

    make.edges.equalTo(self.view);

    }

    如果想更深了解参考这个链接,腾讯Bugly:https://mp.weixin.qq.com/s/W1_0VrchCO50owhJNmJnuQ

    2.状态栏在iPhone X上高度改变。及iPhone X适配

    先看一下iPhone屏幕分辨率

    启动页设置

    规定的就是规定的,没有为什么。最好的方法统一动态加载:

    状态栏(statusbar)

    CGRect StatusRect = [[UIApplication sharedApplication] statusBarFrame];

    //标题栏

    CGRect NavRect = self.navigationController.navigationBar.frame;

    然后将高度相加,计算顶部高度。不再写64

    官方文档: https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/

    3.定位权限

    IOS11,原有的NSLocationAlwaysUsageDeion被降级为NSLocationWhenInUseUsageDeion。因此,在原来项目中使用requestAlwaysAuthorization获取定位权限,而未在plist文件中配置NSLocationAlwaysAndWhenInUseUsageDeion,系统框不会弹出。如:

    4.导航上titleView

    重写此方法完成布局,避免放按钮点击区域改变造成无响应事件。

    - (CGSize)intrinsicContentSize {

    return UILayoutFittingExpandedSize;

    }

    5. 持续更新

    相关文章

      网友评论

          本文标题:iOS11 及iPhone X适配

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