iOS 动画1
来源:互联网 发布:java怎么打成jar 编辑:程序博客网 时间:2024/04/30 20:50
@interface CoreAnimationEffect : NSObject
028
029
#pragma mark - Custom Animation
030
031
/**
032
* @brief 快速构建一个你自定义的动画,有以下参数供你设置.
033
*
034
* @note 调用系统预置Type需要在调用类引入下句
035
*
036
* #import <QuartzCore/QuartzCore.h>
037
*
038
* @param type 动画过渡类型
039
* @param subType 动画过渡方向(子类型)
040
* @param duration 动画持续时间
041
* @param timingFunction 动画定时函数属性
042
* @param theView 需要添加动画的view.
043
*
044
*
045
*/
046
047
+ (
void
)showAnimationType:(NSString *)type
048
withSubType:(NSString *)subType
049
duration:(CFTimeInterval)duration
050
timingFunction:(NSString *)timingFunction
051
view:(UIView *)theView;
052
053
#pragma mark - Preset Animation
054
055
/**
056
* 下面是一些常用的动画效果
057
*/
058
059
// reveal
060
+ (
void
)animationRevealFromBottom:(UIView *)view;
061
+ (
void
)animationRevealFromTop:(UIView *)view;
062
+ (
void
)animationRevealFromLeft:(UIView *)view;
063
+ (
void
)animationRevealFromRight:(UIView *)view;
064
065
// 渐隐渐消
066
+ (
void
)animationEaseIn:(UIView *)view;
067
+ (
void
)animationEaseOut:(UIView *)view;
068
069
// 翻转
070
+ (
void
)animationFlipFromLeft:(UIView *)view;
071
+ (
void
)animationFlipFromRigh:(UIView *)view;
072
073
// 翻页
074
+ (
void
)animationCurlUp:(UIView *)view;
075
+ (
void
)animationCurlDown:(UIView *)view;
076
077
// push
078
+ (
void
)animationPushUp:(UIView *)view;
079
+ (
void
)animationPushDown:(UIView *)view;
080
+ (
void
)animationPushLeft:(UIView *)view;
081
+ (
void
)animationPushRight:(UIView *)view;
082
083
// move
084
+ (
void
)animationMoveUp:(UIView *)view duration:(CFTimeInterval)duration;
085
+ (
void
)animationMoveDown:(UIView *)view duration:(CFTimeInterval)duration;
086
+ (
void
)animationMoveLeft:(UIView *)view;
087
+ (
void
)animationMoveRight:(UIView *)view;
088
089
// 旋转缩放
090
091
// 各种旋转缩放效果
092
+ (
void
)animationRotateAndScaleEffects:(UIView *)view;
093
094
// 旋转同时缩小放大效果
095
+ (
void
)animationRotateAndScaleDownUp:(UIView *)view;
096
097
098
099
#pragma mark - Private API
100
101
/**
102
* 下面动画里用到的某些属性在当前API里是不合法的,但是也可以用.
103
*/
104
105
+ (
void
)animationFlipFromTop:(UIView *)view;
106
+ (
void
)animationFlipFromBottom:(UIView *)view;
107
108
+ (
void
)animationCubeFromLeft:(UIView *)view;
109
+ (
void
)animationCubeFromRight:(UIView *)view;
110
+ (
void
)animationCubeFromTop:(UIView *)view;
111
+ (
void
)animationCubeFromBottom:(UIView *)view;
112
113
+ (
void
)animationSuckEffect:(UIView *)view;
114
115
+ (
void
)animationRippleEffect:(UIView *)view;
116
117
+ (
void
)animationCameraOpen:(UIView *)view;
118
+ (
void
)animationCameraClose:(UIView *)view;
119
120
@end
121
123
124
//
125
// CoreAnimationEffect.m
126
// CoreAnimationEffect
127
//
128
// Created by VincentXue on 13-1-19.
129
// Copyright (c) 2013年 VincentXue. All rights reserved.
130
//
131
132
#import "CoreAnimationEffect.h"
133
134
#import <QuartzCore/QuartzCore.h>
135
136
@implementation CoreAnimationEffect
137
138
/**
139
* 首先推荐一个不错的网站. http://www.raywenderlich.com
140
*/
141
142
#pragma mark - Custom Animation
143
144
+ (
void
)showAnimationType:(NSString *)type
145
withSubType:(NSString *)subType
146
duration:(CFTimeInterval)duration
147
timingFunction:(NSString *)timingFunction
148
view:(UIView *)theView
149
{
150
/** CATransition
151
*
152
* @see http://www.dreamingwish.com/dream-2012/the-concept-of-coreanimation-programming-guide.html
153
* @see http://geeklu.com/2012/09/animation-in-ios/
154
*
155
* CATransition 常用设置及属性注解如下:
156
*/
157
158
CATransition *animation = [CATransition animation];
159
160
/** delegate
161
*
162
* 动画的代理,如果你想在动画开始和结束的时候做一些事,可以设置此属性,它会自动回调两个代理方法.
163
*
164
* @see CAAnimationDelegate (按下command键点击)
165
*/
166
167
animation.delegate = self;
168
169
/** duration
170
*
171
* 动画持续时间
172
*/
173
174
animation.duration = duration;
175
176
/** timingFunction
177
*
178
* 用于变化起点和终点之间的插值计算,形象点说它决定了动画运行的节奏,比如是均匀变化(相同时间变化量相同)还是
179
* 先快后慢,先慢后快还是先慢再快再慢.
180
*
181
* 动画的开始与结束的快慢,有五个预置分别为(下同):
182
* kCAMediaTimingFunctionLinear 线性,即匀速
183
* kCAMediaTimingFunctionEaseIn 先慢后快
184
* kCAMediaTimingFunctionEaseOut 先快后慢
185
* kCAMediaTimingFunctionEaseInEaseOut 先慢后快再慢
186
* kCAMediaTimingFunctionDefault 实际效果是动画中间比较快.
187
*/
188
189
/** timingFunction
190
*
191
* 当上面的预置不能满足你的需求的时候,你可以使用下面的两个方法来自定义你的timingFunction
192
* 具体参见下面的URL
193
*
194
* @see http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CAMediaTimingFunction_class/Introduction/Introduction.html
195
*
196
* + (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
197
*
198
* - (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
199
*/
200
201
animation.timingFunction = [CAMediaTimingFunction functionWithName:timingFunction];
202
203
/** fillMode
204
*
205
* 决定当前对象过了非active时间段的行为,比如动画开始之前,动画结束之后.
206
* 预置为:
207
* kCAFillModeRemoved 默认,当动画开始前和动画结束后,动画对layer都没有影响,动画结束后,layer会恢复到之前的状态
208
* kCAFillModeForwards 当动画结束后,layer会一直保持着动画最后的状态
209
* kCAFillModeBackwards 和kCAFillModeForwards相对,具体参考上面的URL
210
* kCAFillModeBoth kCAFillModeForwards和kCAFillModeBackwards在一起的效果
211
*/
212
213
animation.fillMode = kCAFillModeForwards;
214
215
/** removedOnCompletion
216
*
217
* 这个属性默认为YES.一般情况下,不需要设置这个属性.
218
*
219
* 但如果是CAAnimation动画,并且需要设置 fillMode 属性,那么需要将 removedOnCompletion 设置为NO,否则
220
* fillMode无效
221
*/
222
223
// animation.removedOnCompletion = NO;
224
225
/** type
226
*
227
* 各种动画效果 其中除了'fade', `moveIn', `push' , `reveal' ,其他属于似有的API(我是这么认为的,可以点进去看下注释).
228
* ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.
229
* @"cube" 立方体翻滚效果
230
* @"moveIn" 新视图移到旧视图上面
231
* @"reveal" 显露效果(将旧视图移开,显示下面的新视图)
232
* @"fade" 交叉淡化过渡(不支持过渡方向) (默认为此效果)
233
* @"pageCurl" 向上翻一页
234
* @"pageUnCurl" 向下翻一页
235
* @"suckEffect" 收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向)
236
* @"rippleEffect" 滴水效果,(不支持过渡方向)
237
* @"oglFlip" 上下左右翻转效果
238
* @"rotate" 旋转效果
239
* @"push"
240
* @"cameraIrisHollowOpen" 相机镜头打开效果(不支持过渡方向)
241
* @"cameraIrisHollowClose" 相机镜头关上效果(不支持过渡方向)
242
*/
243
244
/** type
245
*
246
* kCATransitionFade 交叉淡化过渡
247
* kCATransitionMoveIn 新视图移到旧视图上面
248
* kCATransitionPush 新视图把旧视图推出去
249
* kCATransitionReveal 将旧视图移开,显示下面的新视图
250
*/
251
252
animation.type = type;
253
254
/** subtype
255
*
256
* 各种动画方向
257
*
258
* kCATransitionFromRight; 同字面意思(下同)
259
* kCATransitionFromLeft;
260
* kCATransitionFromTop;
261
* kCATransitionFromBottom;
262
*/
263
264
/** subtype
265
*
266
* 当type为@"rotate"(旋转)的时候,它也有几个对应的subtype,分别为:
267
* 90cw 逆时针旋转90°
268
* 90ccw 顺时针旋转90°
269
* 180cw 逆时针旋转180°
270
* 180ccw 顺时针旋转180°
271
*/
272
273
/**
274
* type与subtype的对应关系(必看),如果对应错误,动画不会显现.
275
*
276
* @see http://iphonedevwiki.net/index.php/CATransition
277
*/
278
279
animation.subtype = subType;
280
281
/**
282
* 所有核心动画和特效都是基于CAAnimation,而CAAnimation是作用于CALayer的.所以把动画添加到layer上.
283
* forKey 可以是任意字符串.
284
*/
285
286
[theView.layer addAnimation:animation forKey:nil];
287
}
288
289
#pragma mark - Preset Animation
290
291
292
+ (
void
)animationRevealFromBottom:(UIView *)view
293
{
294
CATransition *animation = [CATransition animation];
295
[animation setDuration:0.35f];
296
[animation setType:kCATransitionReveal];
297
[animation setSubtype:kCATransitionFromBottom];
298
[animation setFillMode:kCAFillModeForwards];
299
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
300
301
[view.layer addAnimation:animation forKey:nil];
302
}
303
304
+ (
void
)animationRevealFromTop:(UIView *)view
305
{
306
CATransition *animation = [CATransition animation];
307
[animation setDuration:0.35f];
308
[animation setType:kCATransitionReveal];
309
[animation setSubtype:kCATransitionFromTop];
310
[animation setFillMode:kCAFillModeForwards];
311
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
312
313
[view.layer addAnimation:animation forKey:nil];
314
}
315
316
+ (
void
)animationRevealFromLeft:(UIView *)view
317
{
318
CATransition *animation = [CATransition animation];
319
[animation setDuration:0.35f];
320
[animation setType:kCATransitionReveal];
321
[animation setSubtype:kCATransitionFromLeft];
322
[animation setFillMode:kCAFillModeForwards];
323
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
324
325
[view.layer addAnimation:animation forKey:nil];
326
}
327
328
+ (
void
)animationRevealFromRight:(UIView *)view
329
{
330
CATransition *animation = [CATransition animation];
331
[animation setDuration:0.35f];
332
[animation setType:kCATransitionReveal];
333
[animation setSubtype:kCATransitionFromRight];
334
[animation setFillMode:kCAFillModeForwards];
335
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
336
337
[view.layer addAnimation:animation forKey:nil];
338
}
339
340
341
+ (
void
)animationEaseIn:(UIView *)view
342
{
343
CATransition *animation = [CATransition animation];
344
[animation setDuration:0.35f];
345
[animation setType:kCATransitionFade];
346
[animation setFillMode:kCAFillModeForwards];
347
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
348
349
[view.layer addAnimation:animation forKey:nil];
350
}
351
352
+ (
void
)animationEaseOut:(UIView *)view
353
{
354
CATransition *animation = [CATransition animation];
355
[animation setDuration:0.35f];
356
[animation setType:kCATransitionFade];
357
[animation setFillMode:kCAFillModeForwards];
358
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
359
360
[view.layer addAnimation:animation forKey:nil];
361
}
362
363
364
/**
365
* UIViewAnimation
366
*
367
* @see http://www.cocoachina.com/bbs/read.php?tid=110168
368
*
369
* @brief UIView动画应该是最简单便捷创建动画的方式了,详解请猛戳URL.
370
*
371
* @method beginAnimations:context 第一个参数用来作为动画的标识,第二个参数给代理代理传递消息.至于为什么一个使用
372
* nil而另外一个使用NULL,是因为第一个参数是一个对象指针,而第二个参数是基本数据类型.
373
* @method setAnimationCurve: 设置动画的加速或减速的方式(速度)
374
* @method setAnimationDuration: 动画持续时间
375
* @method setAnimationTransition:forView:cache: 第一个参数定义动画类型,第二个参数是当前视图对象,第三个参数是是否使用缓冲区
376
* @method commitAnimations 动画结束
377
*/
378
379
+ (
void
)animationFlipFromLeft:(UIView *)view
380
{
381
[UIView beginAnimations:nil context:NULL];
382
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
383
[UIView setAnimationDuration:0.35f];
384
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:NO];
385
[UIView commitAnimations];
386
}
387
388
+ (
void
)animationFlipFromRigh:(UIView *)view
389
{
390
[UIView beginAnimations:nil context:NULL];
391
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
392
[UIView setAnimationDuration:0.35f];
393
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:NO];
394
[UIView commitAnimations];
395
}
396
397
398
+ (
void
)animationCurlUp:(UIView *)view
399
{
400
[UIView beginAnimations:nil context:NULL];
401
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
402
[UIView setAnimationDuration:0.35f];
403
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:view cache:NO];
404
[UIView commitAnimations];
405
}
406
407
+ (
void
)animationCurlDown:(UIView *)view
408
{
409
[UIView beginAnimations:nil context:NULL];
410
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
411
[UIView setAnimationDuration:0.35f];
412
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:view cache:NO];
413
[UIView commitAnimations];
414
}
415
416
+ (
void
)animationPushUp:(UIView *)view
417
{
418
CATransition *animation = [CATransition animation];
419
[animation setDuration:0.35f];
420
[animation setFillMode:kCAFillModeForwards];
421
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
422
[animation setType:kCATransitionPush];
423
[animation setSubtype:kCATransitionFromTop];
424
425
[view.layer addAnimation:animation forKey:nil];
426
}
427
0 0
- iOS 动画1
- iOS核心动画-1
- iOS动画(1)
- iOS 核心动画-1
- IOS开发:动画1
- iOS动画编程-1
- iOS 动画(1)
- iOS动画编程-View动画[ 1 ] 基础View动画
- iOS 动画Animation-1: 动画基础:Block动画
- iOS 动画Animation-2-1: 动画基础:核心动画简介
- IOS基础动画使用1
- iOS-动画 之 Layer(1)
- iOS动画 核心动画
- iOS动画 UIView动画
- iOS动画 CATransition动画
- iOS 动画 UIView动画
- iOS动画-基础动画
- ios 动画
- 对IOS设备中UDID的一些思考
- quick-cocos2dx transition
- WINCE SD 驱动学习
- 越千年,是谁负了这情长
- PHP5加载|安装外部C动态库
- iOS 动画1
- An interested program for cookie
- linux定时任务 掉mysql 存储过程
- win7 x64 下VC6的调试程序无法退出的问题解决方法
- *.tar.gz文件包安装
- win7下架设IIS其他电脑无法访问的解决办法
- 解决MSSQL 2008不能用IP登录的问题
- Hibernate 4中buildSessionFactory()过时
- [Other] Inno Setup 使用心德-一个完整的项目 包括.NET组建捆绑 去空格等