美文网首页效果iOSL的iOS动画
iOS开发中如何给UITableViewCell添加动画

iOS开发中如何给UITableViewCell添加动画

作者: 馒头MT | 来源:发表于2015-03-27 15:14 被阅读4755次

UITableView可以说是iOS开发中最常用的控件了,作为一个高逼格的开发者,肯定不想局限于其平淡无奇的滚动效果,这时候我们就想着往上面倒腾出一些比较有意思的特效,下面来看看如何给UITableViewCell加特效!!

我们需要用到的代理方法:

willDisplayCell,顾名思义,在cell即将显示的时候会调用此方法

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

添加动画操作

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

SDShotCell *shotCell = (SDShotCell *) cell;

CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];

scaleAnimation.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1)];

scaleAnimation.toValue  = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 1)];

scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

[shotCell.layer addAnimation:scaleAnimation forKey:@"transform"];

}

大功告成,很简单的操作,有兴趣还可以研究更多地动效.

271224350203657.gif

相关文章

网友评论

  • 伊织随意写:很赞,提供了很好的思路
  • 57784d7b0696:LZcell复用时,动画会重复加上去吗?这样不影响内存吗?
  • 陶小亮:我有问题,就是 上拉 加载更多数据的时候,那已经展示出来的cell还是会走这个动画的啊。我上拉之后reloadData的。有没有只让新添加的数据走这个动画?
  • Dwyane_Coding:求大神继续分享
  • Easy_VO:在这个方法里可以实现类似于贴吧换一换的效果吗
  • 一帆_iOS程序员:cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 1);
    //设置动画时间为0.25秒,xy方向缩放的最终值为1
    [UIView animateWithDuration:0.5 animations:^{
    cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
    }];
    这样是不是更简单一点...
  • 馒头MT:@宫丞狮 嗯嗯,欢迎多交流哈
  • 51c955f53fcb:@对酒狂歌吃馍 哦 我只是问问 谢谢
  • 馒头MT:@宫丞狮 不会吧,没有发现内存异常.
  • 51c955f53fcb:请问lzcell中添加动画会不会导致内存爆掉

本文标题:iOS开发中如何给UITableViewCell添加动画

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