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

发表于2015-08-17
评论0 559浏览
  看了一些最近放出来的控件, 有些是关于UITableViewCell显示的特效.
  也有朋友问我咋做. 就写了个简单的介绍.

  1、UITableVIew需要实现 - (void)tableView:(UITableView *)tableView willDisplayCell:(TestTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
1
2
3
- (void)""red"">tableView:(UITableView*)""red"">tableView willDisplayCell:(TestTableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath {
    [cellanimationForIndexPath:indexPath];
}


2、UITableViewCell需要实现 - (void)animationForIndexPath:(NSIndexPath *)indexPath
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- (void)animationForIndexPath:(NSIndexPath *)indexPath {
    int row = indexPath.row;
    float radians = (120 + row*30)60;
    radians= 20;
    CALayer*layer = [[self.layersublayers] objectAtIndex:0];
 
    //Rotation Animation
    CABasicAnimation*animation  = [CABasicAnimationanimationWithKeyPath:@"transform.rotation"];
    animation.fromValue=@DEGREES_TO_RADIANS(radians);
    animation.toValue= @DEGREES_TO_RADIANS(0);
     
    //Opacity Animation;
    CABasicAnimation*fadeAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];
    fadeAnimation.fromValue= @0.1f;
    fadeAnimation.toValue= @1.f;
     
    //Translation Animation
    CABasicAnimation*translationAnimation = [CABasicAnimationanimationWithKeyPath:@"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= [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [layeraddAnimation:animationGroup forKey:@"spinAnimation"];
}

3、对应的宏
1
#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)


UITableViewCell的方法实现可以用Category, 也可以用子类.
其实原理非常简单. 想要实现不同的效果, 修改对应的CABasicAnimation就可以了.
发挥想象力最重要.

转载自:http://blog.sina.com.cn/s/blog_53ec65170101errh.html

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引