iOS:UITableView实现飘带动画

这里写图片描述

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

猜你喜欢

转载自blog.csdn.net/liuq0725/article/details/78722549
今日推荐