在 iOS11.的系統上當 UITableView 設置高度固定 rowHeight = xxx; 時,若是tableView滾動到最底部,此時若是刷新tableView會出現tableView向上方跳動一段距離的現象 。佈局
既然只是在iOS 11系統纔會出現這個問題,就研究下iOS 11的一個特性。 iOS 11系統,tableView的加載及顯示cell機制作了調整。atom
產生的緣由是在建立TableViewCelll的時候,系統給加了一個默認預估estimatedRowHeight
的cell高度== UITableViewAutomaticDimension
。spa
參見系統屬性備註:@property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0); // default is UITableViewAutomaticDimension, set to 0 to disable
默認是UITableViewAutomaticDimension
,當設置這個屬性是0的時候,就不會估算cell高度了。.net
iOS 11之後系統默認開啓Self-Sizing,Self-Sizing官方文檔解釋:大概是說咱們不用再本身去計算cell的高度了,只要設置好這兩個屬性,約束好佈局,系統會自動計算好cell的高度,正是這個緣由致使了高度計算出現問題,出現跳動現象。code
將估算高度設置爲0便可:文檔
tableView.estimatedRowHeight = 0;
若是你有使用、加載sectionHeadView或sectionFootView的需求,也會出現閃屏現象,同理將這兩個估算高度設置爲0便可。get
if (@available(iOS 11.0, *)) { self.tableView.estimatedRowHeight = 0; self.tableView.estimatedSectionFooterHeight = 0; self.tableView.estimatedSectionHeaderHeight = 0; }