適配網(wǎng)上文章很多,我只是做個(gè)總結(jié),方便查看。
iOS 11適配:
適配 iOS11 automaticallyAdjustsScrollViewInsets 棄用 和 tableView的HeaderView、FooterView上下邊距過(guò)大
在didFinishLaunchingWithOptions中加入代碼
if (@available(ios 11.0,*)) {
UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
UITableView.appearance.estimatedRowHeight = 0;
UITableView.appearance.estimatedSectionFooterHeight = 0;
UITableView.appearance.estimatedSectionHeaderHeight = 0;
}
還看到一種適配方案,我覺(jué)得更實(shí)際些,就是在有tableView的控制器中加入如下代碼:
self.extendedLayoutIncludesOpaqueBars = YES;
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
self.tableView.contentInset = UIEdgeInsetsMake(64, 0, 49, 0);
self.tableView.scrollIndicatorInsets = self.tableView.contentInset;
iPhone X
關(guān)于iPhone X 你之前的應(yīng)用首次運(yùn)行會(huì)出現(xiàn)上下黑邊的情況
只需要準(zhǔn)備一張iPhone X的啟動(dòng)頁(yè)即可,尺寸為: 1125?×?2436,添加到項(xiàng)目Assets的LaunchImage中
注:LaunchImage中,直接添加可能沒(méi)有iPhone X的尺寸框,網(wǎng)上是改動(dòng)Contents.json,我是直接刪了LaunchImage,又添加了一遍L(zhǎng)aunchImage,就出來(lái)了iPhone X的尺寸框(xcode9自帶)
后面我會(huì)持續(xù)更新...
相關(guān)參考
關(guān)于iOS 11 和 iPhone X 改動(dòng)介紹:
https://www.lee1994.com/guan-yu-iphone/關(guān)于ScrollView新屬性 contentInsetAdjustmentBehavior 代替 automaticallyAdjustsScrollViewInsets
http://www.itdecent.cn/p/1601bd885f83