ios開發之--MJRefresh上拉載入的時候,tableview會向上位移

來源:互聯網
上載者:User

標籤:tableview   row   loaddata   解決方案   llb   初始   view   觀察   沒有   

1,出現這種情況的原因:

這個應該是UITableView最大的改變。我們知道在iOS8引入Self-Sizing之後,我們可以通過實現estimatedRowHeight相關的屬性來展示動態內容,實現了estimatedRowHeight屬性後,得到的初始contenSize是個估算值,是通過estimatedRowHeight乘以 cell的個數得到的,並不是最終的contenSize,只是當前螢幕能夠顯示的cell個數,滑動時,tableView不停地得到新的cell,更新自己的contenSize。

 

    Self-Sizing在iOS11下是預設開啟的,Headers, footers, and cells都預設開啟Self-Sizing,所有estimated高度預設值從iOS11之前的 0改變為UITableViewAutomaticDimension:

 

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

 

2,解決方案,代碼如下:

-(void)creatUI{    communTableV = [[UITableView alloc]initWithFrame:CGRectMake(0, NavHeight, KscreenW, KscreenH-NavHeight-bottomHeight-50) style:UITableViewStylePlain];    communTableV.delegate = self;    communTableV.dataSource = self;    communTableV.tableFooterView = [[UIView alloc]init];    communTableV.tableHeaderView = [self thirdV];    communTableV.estimatedRowHeight = 0;        communTableV.estimatedSectionFooterHeight = 0;        communTableV.estimatedSectionHeaderHeight=0;    if (@available(iOS 11.0, *)) {        communTableV.contentInsetAdjustmentBehavior= UIScrollViewContentInsetAdjustmentNever;    } else {        // Fallback on earlier versions    }if (@available(iOS 11.0, *)) {        communTableV.contentInsetAdjustmentBehavior= UIScrollViewContentInsetAdjustmentNever;    } else {        // Fallback on earlier versions    }        [self.view addSubview:communTableV];}

僅做記錄,別問我為什麼下面的判斷了兩次,是警告點出來的!

ios開發之--MJRefresh上拉載入的時候,tableview會向上位移

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.