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