iOS11適配tableView頂部空白


MJRefresh和繼承自UIScrollView的視圖的iOS 11適配

背景:前兩天一個同行問我了一個問題:

問題
問題

還有就是說如果你使用了 MJRefresh進行刷新,並且你隱藏了導航欄,就會出現下拉刷新錯亂的問題。
這跟我這哥們問的問題是一種類型的,因為 iOS 11上廢除了 automaticallyAdjustsScrollViewInsets這個方法,使用 UIScrollView's contentInsetAdjustmentBehavior來代替,解決辦法就是一段代碼:

OC:

 if (@available(iOS 11.0, *)) {
        self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

swift:

if #available(iOS 11.0, *) {  
    tableView.contentInsetAdjustmentBehavior = .never  
} else {  
    self.automaticallyAdjustsScrollViewInsets = false  
}  

因為哥們是OC寫的項目,大家用的時候注意寫成Swift。

.iOS 11 下tableView的頭視圖和腳視圖

在iOS11里面有時候在tableView的頭部和尾部留白,因為蘋果給滾動試圖加進去了self-sizeing,開始計算逐步計算contentSize,默認如果不去實現viewForHeaderInSection就不會調用heightForHeaderInSection,尾部試圖一樣。

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {  
    return nil  
}  
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {  
    return nil  
}  

如果你不想實現viewForHeaderInSection也不想留白,那么只需要你把self-sizeing自動估高關閉即可

/// 自動關閉估算高度,不想估算那個,就設置那個即可
self.tableView.estimatedRowHeight = 0
self.tableView.estimatedSectionHeaderHeight = 0
self.tableView.estimatedSectionFooterHeight = 0

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM