几个常用的动画

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
使用前
 
         需引入QuartzCore .framework , 并在相关文件中加入 #import "QuartzCore/QuartzCore .h "
 
定义
 
          shakeFeedbackOverlay为UIImageView
 
设置
 
          self .shakeFeedbackOverlay .alpha = 0 .0 ;
 
          self .shakeFeedbackOverlay .layer .cornerRadius = 1 0 .0 ; //设置圆角半径
 
1 、图像左右抖动
 
     CABasicAnimation* shake = [ CABasicAnimation animationWithKeyPath : @"transform.rotation.z" ];
 
     shake .fromValue = [ NSNumber numberWithFloat :-M_PI/ 3 2 ];
 
     shake .toValue = [ NSNumber numberWithFloat :+M_PI/ 3 2 ];
 
     shake .duration = 0 .1 ;
 
     shake .autoreverses = YES ; //是否重复
 
     shake .repeatCount = 4 ;
 
     [ self .shakeFeedbackOverlay .layer addAnimation :shake forKey : @"shakeAnimation" ];
 
     self .shakeFeedbackOverlay .alpha = 1 .0 ;
 
     [ UIView animateWithDuration : 2 .0 delay : 0 .0 options : UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations :^{ self .shakeFeedbackOverlay .alpha = 0 .0 ; //透明度变0则消失 } completion:nil];
 
2 、图像顺时针旋转
 
     CABasicAnimation* shake = [ CABasicAnimation animationWithKeyPath : @"transform.rotation.z" ];
 
     shake .fromValue = [ NSNumber numberWithFloat : 0 ];
 
     shake .toValue = [ NSNumber numberWithFloat : 2 *M_PI];
 
     shake .duration = 0 .8 ; shake .autoreverses = NO ;
 
     shake .repeatCount = 1 ;
 
     [ self .shakeFeedbackOverlay .layer addAnimation :shake forKey : @"shakeAnimation" ];
 
     self .shakeFeedbackOverlay .alpha = 1 .0 ;
 
     [ UIView animateWithDuration : 1 0 .0 delay : 0 .0 options : UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations :^{ self .shakeFeedbackOverlay .alpha = 0 .0 ; } completion :nil ];
 
3 、图像关键帧动画
 
     CAKeyframeAnimation *animation = [ CAKeyframeAnimation animation ];
 
     CGMutablePathRef aPath = CGPathCreateMutable();
 
     CGPathMoveToPoint(aPath, nil , 2 0 , 2 0 );
 
     CGPathAddCurveToPoint(aPath, nil , 1 6 0 , 3 0 , 2 2 0 , 2 2 0 , 2 4 0 , 4 2 0 );
 
     animation .path = aPath;
 
     animation .autoreverses = YES ;
 
     animation .duration = 2 ;
 
     animation .timingFunction = [ CAMediaTimingFunction functionWithName :kCAMediaTimingFunctionEaseOut];
 
     animation .rotationMode = @"auto" ;
 
     [ballView .layer addAnimation :animation forKey : @"position" ];
 
4 、组合动画 CAAnimationGroup
 
     CABasicAnimation *flip = [ CABasicAnimation animationWithKeyPath : @"transform.rotation.y" ];
 
     flip .toValue = [NSNumbernumberWithDouble:-M_PI];
 
     
 
     CABasicAnimation *scale= [ CABasicAnimation animationWithKeyPath : @"transform.scale" ];
 
     scale .toValue = [NSNumbernumberWithDouble: 1 2 ];
 
     scale .duration = 1 .5 ;
 
     scale .autoreverses = YES ;
 
     
 
     CAAnimationGroup *group = [ CAAnimationGroup animation ];
 
     group .animations = [ NSArray arrayWithObjects :flip, scale, nil ];
 
     group .timingFunction = [ CAMediaTimingFunction functionWithName :kCAMediaTimingFunctionEaseInEaseOut];
 
     group .duration = 3 ;
 
     group .fillMode = kCAFillModeForwards;
 
     group .removedOnCompletion = NO ;
 
     [ballView .layer addAnimation :group forKey : @"position" ];
 
5 、指定时间内旋转图片
 
//启动定时器旋转光圈
 
- ( void )startRotate
 
{
 
     self .rotateTimer = [ NSTimer scheduledTimerWithTimeInterval : 0 .02
 
                                                  target : self
 
                                                selector : @selector (rotateGraduation)
 
                                                userInfo :nil
 
                                                 repeats : YES ];
 
}
 
//关闭定时器
 
- ( void )stopTimer
 
{
 
     if ([ self .rotateTimerisValid ])
 
{
 
         [ self .rotateTimerinvalidate ];
 
         self .rotateTimer = nil ;
 
     }
 
}
 
  
 
//旋转动画
 
- ( void )rotateGraduation
 
{
 
     self .timeCount --;
 
     if ( self .timeCount == 0 )
 
     {
 
         [ self stopTimer ];
 
         // doSomeThing //旋转完毕 可以干点别的
 
         self .timeCount = 2 5 ;
 
     }
 
     else
 
     {
 
         //计算角度 旋转
 
         static CGFloat radian = 150 * ( M_2_PI / 3 6 0 );
 
         CGAffineTransform transformTmp = self .lightImageView .transform ;
 
         transformTmp = CGAffineTransformRotate(transformTmp, radian);
 
         self .lightImageView .transform = transformTmp;
 
     };
 
}
 
调用方法
 
self .timeCount = 2 5 ; //动画执行25次
 
[ self startRotate ];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值