直播间聊天滚屏动画

进入直播间的新用户,会有一个历史聊天记录的滚屏效果。本文列举两种

方式一

一次滚动到所有内容底部

-(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];
}

最后demo

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容