iOS 11 与 iPhone X的适配那些事

前言

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

摘要

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

  • 启动App

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

这里写图片描述

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

这里写图片描述

这里写图片描述

这里写图片描述

  • TableView –>MJRefresh

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

@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);

这里提供一些适配用到的宏定义

#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)
#define kTopHeight (kStatusBarHeight + kNavBarHeight)

总结:

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

参考:

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

猜你喜欢

转载自blog.csdn.net/qcx321/article/details/78109658
今日推荐