iOS:UITableView实现飘带动画

来源:互联网 发布:手机淘宝无法安装 编辑:程序博客网 时间:2024/06/06 08:23

这里写图片描述

UITableView实现飘带动画,是利用tableView的reloadData方法,在加载UITableViewCell时改变cell.textLabel 的位置。具体实现如下:

// 设置动画[从左到右飘]__block CGRect frame = cell.textLabel.frame;// 最左边frame.origin = CGPointMake(-tableView.bounds.size.width/2, 0);cell.textLabel.frame = frame;[UIView animateWithDuration:0.5*(1+(double)indexPath.row/4)                 animations:^{                     // 中间                     frame.origin = CGPointMake(tableView.bounds.size.width/2, 0);                     cell.textLabel.frame = frame;               } completion:^(BOOL finished) {                     [UIView animateWithDuration:0.5*(1+(double)indexPath.row/4)                                           delay:2.0 // 停留2秒                                         options:UIViewAnimationOptionCurveEaseInOut                                      animations:^{                                          // 最右边                                        frame.origin = CGPointMake(tableView.bounds.size.width, 0);                                        cell.textLabel.frame = frame;                                    } completion:^(BOOL finished) {                                        if (indexPath.row == 3) { // 动画结束,从头开始                                           [tableView reloadData];                                        }                                 }];}];
原创粉丝点击