UITableViewCell动画

当cell将要显示时调用

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

函数,可以在这里进行Cell内子控件属性的修改,完成所需要的动画效果。

cell动画.gif

代码:

@property (assign, nonatomic) CGFloat lastScrollOffset;
@property (assign, nonatomic) CGFloat move;
- (void)viewDidLoad {
    [super viewDidLoad];
    _move = [UIScreen mainScreen].bounds.size.width;
    _lastScrollOffset = 0;
}

下拉和上拖动画加载的方向不同,先判断手势的的方向

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView != self.tableview) return;
    CGFloat y = scrollView.contentOffset.y;
    if (y > _lastScrollOffset) {//用户往上拖动
        _move = [UIScreen mainScreen].bounds.size.width;
    } else {//用户往下拖动
        _move = -[UIScreen mainScreen].bounds.size.width;
    }
    //存储最后的y值
    _lastScrollOffset = y;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger baseRows = ceilf(CGRectGetHeight(self.tableview.bounds) / 100) - 1;
    CGFloat delay = indexPath.row <= baseRows ? 0.05f * indexPath.row : 0.01f;
    cell.alpha = 0.0;
    cell.transform = CGAffineTransformIdentity;
    CGFloat xMove = _move;
    cell.transform = CGAffineTransformMakeTranslation(xMove, 0);
    
    [UIView animateWithDuration:1.0f delay:delay usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        cell.alpha = 1.0;
        cell.transform = CGAffineTransformMakeTranslation(0, 0);
    } completion:^(BOOL finished) {
        
    }];
}

NSInteger baseRows = ceilf(CGRectGetHeight(self.tableview.bounds) / 100) - 1;中的100是cell的高度。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我们在上一篇《通过代码自定义不等高cell》中学习了tableView的相关知识,本文将在上文的基础上,利用sto...
    啊世ka阅读 1,543评论 2 7
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,259评论 4 61
  • 1.badgeVaule气泡提示 2.git终端命令方法> pwd查看全部 >cd>ls >之后桌面找到文件夹内容...
    i得深刻方得S阅读 4,775评论 1 9
  • 关于企业的渗透测试流程 针对企业的网络服务 前期交互Pre-Engagement Interaction 这个阶段...
    青山i阅读 1,301评论 0 14
  • 按照老规矩,罗列一下工具和平台: MSP-EXP430F5229 开发板,自带ez-FET仿真器 TI Compo...
    浮生一城阅读 2,382评论 0 3