iOS 11 注意點

1.TableView
在iOS 11中默認啟用Self-Sizing 未使用AutoLayout的TableView中的高度會出現(xiàn)問題.

  • Self-Sizing在iOS11下是默認開啟的,Headers, footers, and cells都默認開啟Self-Sizing,所有estimated 高度默認值從iOS11之前的 0 改變?yōu)閁ITableViewAutomaticDimension.

如果目前項目中沒有使用estimateRowHeight屬性,在iOS11的環(huán)境下就要注意了,因為開啟Self-Sizing之后,tableView是使用estimateRowHeight屬性的,這樣就會造成contentSize和contentOffset值的變化,如果是有動畫是觀察這兩個屬性的變化進行的,就會造成動畫的異常,因為在估算行高機制下,contentSize的值是一點點地變化更新的,所有cell顯示完后才是最終的contentSize值。
因為不會緩存正確的行高,tableView reloadData的時候,會重新計算contentSize,就有可能會引起contentOffset的變化。iOS11下不想使用Self-Sizing的話,可以通過以下方式關(guān)閉:

self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;

1.TableView 中,如果設(shè)置了tableview的tableFooterView

_mainTableView.tableFooterView = self.footerView;

那么, 需要實現(xiàn)tableview的下面的幾個代理方法,向上面那樣把 estimatedRowHeight , estimatedSectionHeaderHeight, estimatedSectionFooterHeight 都置為0,是不好使的,第一個cell還是會下移

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容