首页 > 代码库 > CABasiAnimation的变化属性

CABasiAnimation的变化属性

transform.scale = 比例轉換

    transform.scale.x = 闊的比例轉換

    transform.scale.y = 高的比例轉換

    transform.rotation.z = 平面圖的旋轉

    opacity = 透明度

    margin

    zPosition

    backgroundColor    背景颜色

    cornerRadius    圆角

    borderWidth

    bounds

    contents

    contentsRect

    cornerRadius

    frame

    hidden

    mask

    masksToBounds

    opacity

    position

    shadowColor

    shadowOffset

    shadowOpacity

    shadowRadius

下面是一些例子

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    pulse.duration = 0.5 + (rand() % 10) * 0.05;
    pulse.repeatCount = 1;
    pulse.autoreverses = YES;
    pulse.fromValue = http://www.mamicode.com/[NSNumber numberWithFloat:.8];
    pulse.toValue = http://www.mamicode.com/[NSNumber numberWithFloat:1.2];
    [self.ui_View.layer addAnimation:pulse forKey:nil];
 
// bounds
  
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"bounds"];
    anim.duration = 1.f;
    anim.fromValue = http://www.mamicode.com/[NSValue valueWithCGRect:CGRectMake(0,0,10,10)];
    anim.toValue = http://www.mamicode.com/[NSValue valueWithCGRect:CGRectMake(10,10,200,200)];
    anim.byValue  = [NSValue valueWithCGRect:self. ui_View.bounds];
//    anim.toValue = http://www.mamicode.com/(id)[UIColor redColor].CGColor;
//    anim.fromValue =http://www.mamicode.com/ (id)[UIColor blackColor].CGColor;
     
    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    anim.repeatCount = 1;
    anim.autoreverses = YES;
     
    [ui_View.layer addAnimation:anim forKey:nil];
//cornerRadius
  
    CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];
    anim2.duration = 1.f;
    anim2.fromValue = http://www.mamicode.com/[NSNumber numberWithFloat:0.f];
    anim2.toValue = http://www.mamicode.com/[NSNumber numberWithFloat:20.f];
    anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    anim2.repeatCount = CGFLOAT_MAX;
    anim2.autoreverses = YES;
     
    [ui_View.layer addAnimation:anim2 forKey:@"cornerRadius"];
 
//contents
  
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"contents"];
    anim.duration = 1.f;
    anim.fromValue = http://www.mamicode.com/(id)[UIImage imageNamed:@"1.jpg"].CGImage;
    anim.toValue = http://www.mamicode.com/(id)[UIImage imageNamed:@"2.png"].CGImage;
//    anim.byValue  = (id)[UIImage imageNamed:@"3.png"].CGImage;
//    anim.toValue = http://www.mamicode.com/(id)[UIColor redColor].CGColor;
//    anim.fromValue =http://www.mamicode.com/ (id)[UIColor blackColor].CGColor;
     
    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    anim.repeatCount = CGFLOAT_MAX;
    anim.autoreverses = YES;
     
    [ui_View.layer addAnimation:anim forKey:nil];
 
 
  
[ui_View.layer setShadowOffset:CGSizeMake(2,2)];
    [ui_View.layer setShadowOpacity:1];
    [ui_View.layer setShadowColor:[UIColor grayColor].CGColor];
//
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowColor"];
    anim.duration = 1.f;
    anim.toValue = http://www.mamicode.com/(id)[UIColor redColor].CGColor;
    anim.fromValue =http://www.mamicode.com/ (id)[UIColor blackColor].CGColor;
     
    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    anim.repeatCount = CGFLOAT_MAX;
    anim.autoreverses = YES;
     
    [ui_View.layer addAnimation:anim forKey:nil];
     
    CABasicAnimation *_anim = [CABasicAnimation animationWithKeyPath:@"shadowOffset"];
    _anim.duration = 1.f;
    _anim.fromValue = http://www.mamicode.com/[NSValue valueWithCGSize:CGSizeMake(0,0)];
    _anim.toValue = http://www.mamicode.com/[NSValue valueWithCGSize:CGSizeMake(3,3)];
     
    _anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    _anim.repeatCount = CGFLOAT_MAX;
    _anim.autoreverses = YES;
     
    [ui_View.layer addAnimation:_anim forKey:nil];
     
     
    CABasicAnimation *_anim1 = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
    _anim1.duration = 1.f;
    _anim1.fromValue = http://www.mamicode.com/[NSNumber numberWithFloat:0.5];
    _anim1.toValue = http://www.mamicode.com/[NSNumber numberWithFloat:1];
     
    _anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    _anim1.repeatCount = CGFLOAT_MAX;
    _anim1.autoreverses = YES;
     
    [ui_View.layer addAnimation:_anim1 forKey:nil];
     
     
     
    CABasicAnimation *_anim2 = [CABasicAnimation animationWithKeyPath:@"shadowRadius"];
    _anim2.duration = 1.f;
    _anim2.fromValue = http://www.mamicode.com/[NSNumber numberWithFloat:10];
    _anim2.toValue = http://www.mamicode.com/[NSNumber numberWithFloat:5];
     
    _anim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    _anim2.repeatCount = CGFLOAT_MAX;
    _anim2.autoreverses = YES;
     
    [ui_View.layer addAnimation:_anim2 forKey:nil];

 下面是一些应用

 

几个可以用来实现热门APP应用PATH中menu效果的几个方法
 
+(CABasicAnimation *)opacityForever_Animation:(float)time //永久闪烁的动画
 
{
 
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];
 
    animation.fromValue=http://www.mamicode.com/[NSNumber numberWithFloat:1.0];
 
    animation.toValue=http://www.mamicode.com/[NSNumber numberWithFloat:0.0];
 
    animation.autoreverses=YES;
 
    animation.duration=time;
 
    animation.repeatCount=FLT_MAX;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    return animation;
 
}
 
  
 
+(CABasicAnimation *)opacityTimes_Animation:(float)repeatTimes durTimes:(float)time; //有闪烁次数的动画
 
{
 
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];
 
    animation.fromValue=http://www.mamicode.com/[NSNumber numberWithFloat:1.0];
 
    animation.toValue=http://www.mamicode.com/[NSNumber numberWithFloat:0.4];
 
    animation.repeatCount=repeatTimes;
 
    animation.duration=time;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
 
    animation.autoreverses=YES;
 
    return  animation;
 
}
 
  
 
+(CABasicAnimation *)moveX:(float)time X:(NSNumber *)x //横向移动
 
{
 
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
 
    animation.toValue=http://www.mamicode.com/x;
 
    animation.duration=time;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    return animation;
 
}
 
  
 
+(CABasicAnimation *)moveY:(float)time Y:(NSNumber *)y //纵向移动
 
{
 
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
 
    animation.toValue=http://www.mamicode.com/y;
 
    animation.duration=time;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    return animation;
 
}
 
  
 
+(CABasicAnimation *)scale:(NSNumber *)Multiple orgin:(NSNumber *)orginMultiple durTimes:(float)time Rep:(float)repeatTimes //缩放
 
{
 
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
 
    animation.fromValue=http://www.mamicode.com/orginMultiple;
 
    animation.toValue=http://www.mamicode.com/Multiple;
 
    animation.duration=time;
 
    animation.autoreverses=YES;
 
    animation.repeatCount=repeatTimes;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    return animation;
 
}
 
  
 
+(CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes //组合动画
 
{
 
    CAAnimationGroup *animation=[CAAnimationGroup animation];
 
    animation.animations=animationAry;
 
    animation.duration=time;
 
    animation.repeatCount=repeatTimes;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    return animation;
 
}
 
  
 
+(CAKeyframeAnimation *)keyframeAniamtion:(CGMutablePathRef)path durTimes:(float)time Rep:(float)repeatTimes //路径动画
 
{
 
    CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
 
    animation.path=path;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
 
    animation.autoreverses=NO;
 
    animation.duration=time;
 
    animation.repeatCount=repeatTimes;
 
    return animation;
 
}
 
  
 
+(CABasicAnimation *)movepoint:(CGPoint )point //点移动
 
{
 
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation"];
 
    animation.toValue=http://www.mamicode.com/[NSValue valueWithCGPoint:point];
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    return animation;
 
}
 
  
 
+(CABasicAnimation *)rotation:(float)dur degree:(float)degree direction:(int)direction repeatCount:(int)repeatCount //旋转
 
{
 
    CATransform3D rotationTransform  = CATransform3DMakeRotation(degree, 0, 0,direction);
 
    CABasicAnimation* animation;
 
    animation = [CABasicAnimation animationWithKeyPath:@"transform"];
 
  
 
animation.toValue= http://www.mamicode.com/[NSValue valueWithCATransform3D:rotationTransform];
 
    animation.duration= dur;
 
animation.autoreverses= NO;
 
    animation.cumulative= YES;
 
    animation.removedOnCompletion=NO;
 
    animation.fillMode=kCAFillModeForwards;
 
    animation.repeatCount= repeatCount;
 
animation.delegate= self;
 
  
 
return animation;
 
}

CABasiAnimation的变化属性