美文网首页
tableView cell动画

tableView cell动画

作者: 林希品 | 来源:发表于2021-11-19 15:09 被阅读0次

简单的UITableViewCell特效 飞入飞出之类的

1. UITableVIew需要实现 - (void)tableView:(UITableView *)tableView willDisplayCell:(TestTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

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

    [cell animationForIndexPath:indexPath];

}

2. UITableViewCell需要实现 - (void)animationForIndexPath:(NSIndexPath *)indexPath

- (void)animationForIndexPath:(NSIndexPath*)indexPath {

    introw = indexPath.row;

    floatradians = (120 + row*30)%360;

    radians = 20;

    CALayer *layer = [[self.layer sublayers] objectAtIndex:0];

    // Rotation Animation

    CABasicAnimation *animation  = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

    animation.fromValue =@DEGREES_TO_RADIANS(radians);

    animation.toValue =@DEGREES_TO_RADIANS(0);

    // Opacity Animation;

    CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

    fadeAnimation.fromValue =@0.1f;

    fadeAnimation.toValue =@1.f;

    // Translation Animation

    CABasicAnimation *translationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];

    ;

    translationAnimation.fromValue = @(-300.f * ((indexPath.row%2 == 0) ? -1: 1));

    translationAnimation.toValue =@0.f;

    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];

    animationGroup.duration = 0.4f;

    animationGroup.animations = @[animation,fadeAnimation,translationAnimation];

    animationGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [layer addAnimation:animationGroup forKey:@"spinAnimation"];

}

3. 对应的宏

#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)

相关文章

网友评论

      本文标题:tableView cell动画

      本文链接:https://www.haomeiwen.com/subject/qtalzltx.html