适配iOS11和iPhoneX

/ 0评 / 0

iOS11正式版来了,昨天我也把app适配了一下,其实也不是很麻烦,来看看我做的一些操作

1、UITableView、UICollectionView的变化

tableView在iOS11默认使用Self-Sizing,tableView的estimatedRowHeight、estimatedSectionHeaderHeight、 estimatedSectionFooterHeight三个高度估算属性由默认的0变成了UITableViewAutomaticDimension,所以当你pop回来的时候发现tableView自己动了,钥匙胚关掉他们就行了,collectionView也是一样的

if (@available(iOS 11.0, *)) {
    tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    //其实验证上面一句就行了,下面这三句比较极端
    tableView.estimatedRowHeight = 0;
    tableView.estimatedSectionHeaderHeight = 0;
    tableView.estimatedSectionFooterHeight = 0;
}

//swift写法
if #available(iOS 11.0, *) {  
    tableView.contentInsetAdjustmentBehavior = .never  
} else {  
    self.automaticallyAdjustsScrollViewInsets = false  
} 

2、iPhoneX来袭

由于iPhoneX出来了,屏幕太大,没有HOME键,出现了safeArea的概念,就是安全使用的区域嘛,所以如果你使用了Masonry,那么你需要适配safeArea

if (@available(iOS 11.0, *)) {
    make.edges.equalTo()(self.view.safeAreaInsets)
} else {
    make.edges.equalTo()(self.view)
}

另外你会发现iPhoneX上启动之后tabbar上移了,其实是启动图太小啦,赶紧勾选iOS 8.0 and later Portrait ,然后来张来张3x(1125 * 2436)的启动图放上就OK了。
当然还有其他很多变化呢,比如状态栏加导航栏不再是64了等等,问题多多呀,慢慢研究。

评论已关闭。