"MindManager"学习iOS系列之"CAAnimation-核心动画"详解,思惟导图内展现了CAAnimation-核心动画的大多数基本功能和知识,每一个part都有代码讲解,展现出CAAnimation-核心动画的清晰轮廓,编者提供了"JPG"、"SWF"、"PDF"、"Word"、"Mmap"格式的源文件供给使用。注意:JPG格式仅为图片总览,SWF格式使用微软IE浏览器浏览便可,Word以全文本形式给出框架图,Mmap格式体会MindManager的魅力。To Be Continue,CAAnimation-核心动画的新知识,新想法,新思路慢慢更新,欢迎提出宝贵建议。浏览器
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-框架
iAronTalk Blog opens.函数
The study certainly is not the life complete. But, since continually life part of - studies also is unable to conquer, what but also can make?学习
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-动画
各类类型文件的下载地址:http://pan.baidu.com/s/1pJnBtLhspa
在iOS中随处均可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带你们一窥iOS动画全貌。在这里你能够看到iOS中如何使用图层精简非交互式绘图,如何经过核心动画建立基础动画、关键帧动画、动画组、转场动画,如何经过UIView的装饰方法对这些动画操做进行简化等。在今天的文章里您能够看到动画操做在iOS中是如何简单和高效,不少原来想作可是苦于没有思路的动画在iOS中将变得愈加简单。代理
每一个小知识点中都有相应的demo说明。orm
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-对象
后续会将集成导出的word内容展现在后面,系统自动集成,与做者原用意略有差别,使用SWF"、"PDF"、"Mmap"格式最佳。 blog
Core Animation CAAnimation (抽象类)
1 继承结构CAAnimation
1.1 CATransition
1.2 CAAnimationGroup
1.3 CAPropertyAnimation 抽象类
1.3.1 CABasicAnimation
1.3.2 CAKeyFrameAnimation
2 何为CAAnimation
2.1 CAAnimation性格分析
2.2 属性
参阅: 协议属性
·removedOnCompletion:默认为YES,表明动画执行完毕后就从图层上移除,图形会恢复到 动画执行前的状态。
若是想让图层保持显示动画执行后的状态,那就设置为NO,不过还要设置fillMode为 kCAFillModeForwards
·timingFunction:速度控制函数,控制动画运行的节奏
·delegate:动画代理
·fillMode属性 (要想fillMode有效,最好设置removeOnCompletion = NO)
·kCAFillModeRemoved 默认值,动画开始前和动画结束后,动画对layer都没有影
响,动画结束后,layer会恢复到动画开始前的状态
·kCAFillModeForwards 当动画结束后,layer会保持动画最后的显示状态
·kCAFillModeBackwards 在动画开始前,只须要将动画加入了一个layer, layer便
当即进入动画的初始状态并等待动画的开始
·kCAFillModeBoth 上面两个的合成,动画加入后开始前,layer便处于动画初始状
态,动画结束后layer保持动画最后的状态
·速度控制函数(CAMediaTimingFunction)
·kCAMediaTimingFunctionLinear(线性):匀速,给你一个相对静态的感受
·kCAMediaTimingFunctionEaseIn(渐进):动画缓慢进入,而后加速离开
·kCAMediaTimingFunctionEaseOut(渐出):动画全速进入,而后减速的到
达目的地
·kCAMediaTimingFunctionEaseInEaseOut(渐进渐出):动画缓慢的进
入,中间加速,而后减速的到达目的地。这个是默认的动画行为。
3 CAMediaTiming(协议)
3.1 协议属性
·duration:动画的持续时间
·repeatCount:重复次数,无限循环能够设置HUGE_VALF或者MAXFLOAT
·repeatDuration:重复时间
·fillMode:决定当前对象在非active时间段的行为。好比动画开始以前或者动画结束以后
·CACurrentMediaTime()为图层的当前时间
·beginTime:能够用来设置动画延迟执行时间,若想延迟2s,就设置为 CACurrentMediaTime()+2。
4 Main Topic
5 进入CCAnimation的世界
5.1 CATransition
1) CATransition是CAAnimation的子类,用于作转场动画,可以为层提供移出
屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点
2) UINavigationController就是经过CATransition实现了将控制器的视图推入屏
幕的动画效果.
3) 动画属性:
·type:动画过渡类型
·subtype:动画过渡方向
·startProgress:动画起点(在总体动画的百分比)
·endProgress:动画终点(在总体动画的百分比)
4) type:动画过渡类型,如图:
5)
5.1.1 .h
// ViewController.h
// CAAnimation03
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIView *_superView;
}
@end
5.1.2 .m
// ViewController.m
// CAAnimation03
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 核心动画
// 1.建立视图
_superView = [[UIView alloc] initWithFrame:self.view.bounds];
_superView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_superView];
// 01 建立视图1
UIView *view1 = [[UIView alloc] initWithFrame:self.view.bounds];
view1.backgroundColor = [UIColor orangeColor];
[_superView addSubview:view1];
// 02 建立视图2
UIView *view2 = [[UIView alloc] initWithFrame:self.view.bounds];
view2.backgroundColor = [UIColor redColor];
[_superView addSubview:view2];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// 1.建立动画对象
CATransition *transition = [CATransition animation];
transition.duration = .35;
// 设置加速方式
transition.timingFunction = [CAMediaTimingFunction functionWithName:@"default"];
// 设置动画样式
//·type:动画过渡类型
//·subtype:动画过渡方向
transition.type = @"cameraIrisHollowOpen";
transition.subtype = kCATransitionFromRight;
[_superView.layer addAnimation:transition forKey:@"transition"];
// 切换视图
[_superView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
}
@end
5.2 CABasicAnimation
5.2.1 .h
// ViewController.h
// CABasicAnimation04
//
//
本例使用storyboard建立,适合有点基础的学习。
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
UIView *_subView;
// 暂停的事件
CFTimeInterval _timeInterval;
// 当前暂停时刻
CFTimeInterval _newStopTime;
}
- (IBAction)startAction:(id)sender;
- (IBAction)stopAction:(id)sender;
- (IBAction)remveAction:(id)sender;
@end
5.2.2 .m
// ViewController.m
// CABasicAnimation04
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_subView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
_subView.backgroundColor = [UIColor redColor];
[self.view addSubview:_subView];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 使用CABasicAnimation设置动画
CABasicAnimation*basic=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
// 设置开始位置
basic.fromValue = @(0);
basic.toValue = @(M_PI * 2);
// 设置动画执行完成的一个状态
basic.fillMode = kCAFillModeForwards;
basic.removedOnCompletion = NO;
// 配置动画事件
basic.duration = 2;
basic.repeatCount = 100;
// 还原的时候也有动画效果
basic.autoreverses = NO;
[_subView.layer addAnimation:basic forKey:@"basicKey"];
}
- (IBAction)startAction:(id)sender {
// 恢复动画
// 1.恢复速度
_subView.layer.speed = 1.0;
// 2.设置延迟实行事件
_timeInterval += CACurrentMediaTime() - _newStopTime;
_subView.layer.beginTime = _timeInterval;
NSLog(@"%f",_subView.layer.timeOffset);
// 3.取消以前的位置设置
_subView.layer.timeOffset = 0;
}
- (IBAction)stopAction:(id)sender {
// 设置layer的移动速度为0,至关于中止了
_subView.layer.speed = 0.0;
// 设置layer位置,是相对于时间的位置
_newStopTime = CACurrentMediaTime();
_subView.layer.timeOffset = _newStopTime;
}
- (IBAction)remveAction:(id)sender {
[_subView.layer removeAnimationForKey:@"basicKey"];
}
@end
5.3 CAKeyFrameAnimation
5.4 CAAnimationGroup
未完待续。
-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
因为编者水平有限,不妥之处在所不免,恳请各个大牛批评指正,提出宝贵建议。