进入直播间的新用户,会有一个历史聊天记录的滚屏效果。本文列举两种
方式一
一次滚动到所有内容底部
-(void)showAddDataWithAnimation{
//方式一:一次滚动到底部
NSMutableArray *array = [[NSMutableArray alloc] init];
for(NSString *value in self.toAddData){
[self.tableData addObject:value];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.tableData.count-1 inSection:0];
[array addObject:indexPath];
}
[self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
[self.tableView scrollToRowAtIndexPath:array.lastObject atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[UIView animateWithDuration:1 animations:^{
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}];
}
方式二
一条一条的滚动
-(void)addDataWithOneByOneAnimation{
//方式二:一条一条滚动
[self.tableData addObject:self.toAddData.firstObject];
[self.toAddData removeObjectAtIndex:0];
if(self.toAddData.count == 0){
[self.timer invalidate];
self.timer = nil;
[UIView animateWithDuration:1 animations:^{
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}];
}
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.tableData.count-1 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}