iOS10 以下版本 self.view的y會(huì)從頂部toolBar的y開始計(jì)算.
在iOS7中, 蘋果引入了一個(gè)新的屬性, 叫做
UIViewController.edgesForExtendedLayout, 他的默認(rèn)值是all, 當(dāng)你的容器是navigationController時(shí), 默認(rèn)的布局將從navigationBar的頂部開始. 這就是為什么所有的UI元素都往上偏移了44pt. 有時(shí)候還會(huì)加上頂部toolBar的高度20, 而且下面的tabbar也縮進(jìn)49.
解決辦法: 設(shè)置edgesForExtendedLayout = UIRectEdge.init()
如果設(shè)置成edgesForExtendedLayout = UIRectEdge.bottom; 那么就會(huì)self.view.frame是從navigationBar下面開始計(jì)算一直到屏幕底部.
如果設(shè)置成edgesForExtendedLayout = UIRectEdge.init(); 那么就會(huì)self.view.frame是從navigationBar下面開始計(jì)算 一直到屏幕tabbar上部.
如果設(shè)置成edgesForExtendedLayout = UIRectEdge.top; 那么就會(huì)self.view.frame是從navigationBar上面計(jì)算, 一直到屏幕tabbar上部.在iOS11 以下的系統(tǒng), 隱藏導(dǎo)航欄之后, 滑動(dòng)視圖會(huì)向下偏移狀態(tài)欄的高度. 解決辦法:
項(xiàng)目中用到的tableView 或者 scrollView 在Xib中已經(jīng)設(shè)置過contentInsetAdjustmentBehavior = never. 但是沒有適配低版本的系統(tǒng)設(shè)置. 在iOS11 以下版本中要設(shè)置self.automaticallyAdjustsScrollViewInsets = false; 代碼為:
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = UIScrollView.ContentInsetAdjustmentBehavior.never
} else {
automaticallyAdjustsScrollViewInsets = false
}