1.滾動(dòng)到最后一行
- (void)scrollToBottom
{
? ? if ([UIDevice isIphone6] || [UIDevice isIphone6p]) {
? ? ? ? if (self.fpmModel.responseData.count > 0) {
? ? ? ? ? ? [self.messageTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.fpmModel.responseData.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
? ? ? ? }
? ? }else{
? ? ? ? if (self.messageTableView.contentSize.height > self.messageTableView.bounds.size.height) {
? ? ? ? ? ? [self.messageTableView setContentOffset:CGPointMake(0, self.messageTableView.contentSize.height -self.messageTableView.bounds.size.height) animated:NO];
? ? ? ? }
? ? }
}
iPhone5及其以下
2.解決跳屏問題(明顯的刷新)
對(duì)于iPhone5以下設(shè)備,由于CPU處理速度較慢,感覺不到跳屏問題,但在iPhone6以上設(shè)備,CPU處理速度很快,為了避免明顯的跳屏,要延遲100毫秒等待數(shù)據(jù)刷新完畢再滾動(dòng)。
注意:該地方的延遲處理是延遲滾動(dòng),當(dāng)數(shù)據(jù)源很多的時(shí)候,滾動(dòng)瞬間就能滾動(dòng)到最后一行,但要展示最后一行的數(shù)據(jù),在Cell比較復(fù)雜的時(shí)候可能會(huì)稍微慢,所以會(huì)出現(xiàn)跳屏問題,而在慢設(shè)備上滾動(dòng)的處理較慢,故感覺不到跳屏。
[self.messageTableView reloadData];
? ? ? ? ? ? // 延遲100毫秒等待數(shù)據(jù)刷新完畢
? ? ? ? ? ? dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1*NSEC_PER_SEC));
? ? ? ? ? ? dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
? ? ? ? ? ? ? ? [self scrollToBottom];
? ? ? ? ? ? });