iOS 11 与 iPhone X的适配那些事

前言

9月20日,正式推送Xcode 9 和iOS 11 的正式版,适配iOS 11是首要的适配的,网上教程很多,不在赘述。这里主要讲的是 iPhone X的适配。大神级别的可以不用看,我这里讲的主要是基础的适配工作

摘要

启动图: 1125 * 2436
statusBar高度: 44
tabbar高度: 83

  • 启动App

对于一些老项目,在启动图上,可能没有采用xib或者SB进行适配的,所以可能会出现如图一,这样导致整个项目运行就会不能完全贴合。

![Uploading login2_194373.png . . .]

解决办法,在项目设置里面直接用LaunchScreen.xib或者LaunchScreen.storyboard进行配置启动图,这样项目就会完整显示了


iPhone X LaunchImage.png

iPhone X LaunchImage2.png
login2.png

出现下拉刷新的尾巴,该问题很好解决,在文档中标注很明白

@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets API_DEPRECATED_WITH_REPLACEMENT("Use UIScrollView's contentInsetAdjustmentBehavior instead", ios(7.0,11.0),tvos(7.0,11.0)); // Defaults to YES

contentInsetAdjustmentBehavior对于我们现在来说是个陌生面孔。这是在iOS11中为ScrollView新定义的一个枚举属性。注意,上面谈到的automaticallyAdjustsScrollViewInsets是控制器的属性。

typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
    UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
    UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
    UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted
    UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets
} API_AVAILABLE(ios(11.0),tvos(11.0));

iOS 11中的estimatedXXHeight由默认的0变成了现在的默认.AutomaticDimension,导致高度计算出错,最后导致的现象就是上拉加载更多的时候UI错乱,TableView视图的高度异常等一系列问题。

 if (@available(iOS 11.0, *)) {
        _newtableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        //以下是tableview高度计算出现问题
        _newtableView.estimatedRowHeight = 0;
        _newtableView.estimatedSectionHeaderHeight=0;
        _newtableView.estimatedSectionFooterHeight=0;
        
  }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
  }

iOS 11 NavigationBar 新特性

Navigation 集成 UISearchController
把你的UISearchController赋值给navigationItem,就可以实现将UISearchController集成到Navigation

navigationItem.searchController  //iOS 11 新增属性
navigationItem.hidesSearchBarWhenScrolling //决定滑动的时候是否隐藏搜索框;iOS 11 新增属性
@property (nonatomic, retain, nullable) UISearchController *searchController API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

总结:

iOS11系统改变还是比较大的,某些地方需要注意适配,不然会出现很奇怪的现象。暂时,在iOS11遇到这么多坑,以后遇到会继续分享的。
第一次写文章,多谢关照

参考:

开发者所需要知道的 iOS 11 SDK 新特性
iOS 11导航栏高度自定义
iOS 11 UIKit の変更点

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 随着iOS11和xcode9刚开始正式发布,小编也迫不及待的更新了xcode9,手机也顺利更新到iOS,也终于见到...
    七秒记忆的鱼儿阅读 96,415评论 97 410
  • iOS11与iPhone X的适配 文章讲解点:1.首先看一下iPhone X的模拟器样式吧2.iPhone X的...
    iYeso阅读 486评论 0 3
  • 苹果公司于2017年9月13日凌晨发布了两款新的手机—— iPhon 8与iPhone X,作为全新的屏幕样式 i...
    LearningCoding阅读 6,099评论 2 6
  • 会认识林然真的可以说是天注定。 十一黄金周,李笑决定在家里宅到死。好不容易休息几天她才不会想不开去旅游呢!这个时候...
    淡紫褐绿阅读 671评论 2 2
  • 成功的路上没有人会叫你起床,也没有人为你买单,你需要自我管理,自我约束,自我突破,人都是被逼出来的,人的潜能无限,...
    wanghaokang阅读 223评论 0 0