iOS 11 設(shè)備上運(yùn)行出現(xiàn)最多問(wèn)題應(yīng)該就是 tableView 莫名奇妙地偏移了 20pt 或者 64pt。原因是 iOS 11 棄用了 automaticallyAdjustsScrollViewInsets 屬性,取而代之的是 UIScrollView 新增了 contentInsetAdjustmentBehavior 屬性,這一切的罪魁禍?zhǔn)锥际切乱氲?Safe Area。Safe Area 幫助我們將 view 放置在整個(gè)屏幕的可視的部分。即使把 navigationBar 設(shè)置為透明,系統(tǒng)也認(rèn)為安全區(qū)域是從 navigationBar 的 bottom 開(kāi)始的。

1506312020119835.png
解決方法
/**
在AppDelegate中didFinishLaunchingWithOptions或其他適當(dāng)位置調(diào)用以下方法即可解決
解決iOS11上因安全區(qū)域?qū)е碌腢ITableView或UIScrollView偏移的問(wèn)題
*/
+ (void)dealWithiOS11SafeAreaIssue{
//解決iOS11,僅實(shí)現(xiàn)heightForHeaderInSection,沒(méi)有實(shí)現(xiàn)viewForHeaderInSection方法時(shí),section間距大的問(wèn)題
[UITableView appearance].estimatedRowHeight = 0;
[UITableView appearance].estimatedSectionHeaderHeight = 0;
[UITableView appearance].estimatedSectionFooterHeight = 0;
//iOS11 解決SafeArea的問(wèn)題,同時(shí)能解決pop時(shí)上級(jí)頁(yè)面scrollView抖動(dòng)的問(wèn)題
if (@available(iOS 11, *)) {
[UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; //iOS11 解決SafeArea的問(wèn)題,同時(shí)能解決pop時(shí)上級(jí)頁(yè)面scrollView抖動(dòng)的問(wèn)題
}
}