您的位置:首页 > 其它

核心动画的接触点滴(二)

2016-05-30 12:25 295 查看
本篇记录核心动画中基础动画的使用:

一、简单介绍 CAPropertyAnimation的子类 属性解析: fromValue:keyPath相应属性的初始值 toValue:keyPath相应属性的结束值 随着动画的进行,在长度为duration的持续时间内,keyPath相应属性的值从fromValue渐渐地变为toValue 如果fillMode=kCAFillModeForwards和removedOnComletion=NO,那么在动画执行完毕后,图层会保持显示动画执行 后的状态。但在实质上,图层的属性值还是动画执行前的初始值,并没有真正被改变。 比如,CALayer的position初始值为(0,0),CABasicAnimation的fromValue为(10,10),toValue为(100,100),虽然动 画执行完毕后图层保持在(100,100)这个位置,实质上图层的position还是为(0,0)二、平移动画
//1.创建核心动画38
CABasicAnimation *anima=[CABasicAnimation animation];

//1.1告诉系统要执行什么样的动画
anima.keyPath=@"position";

//设置通过动画,将layer从哪儿移动到哪儿
anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)];

//1.2设置动画执行完毕之后不删除动画
anima.removedOnCompletion=NO;

//1.3设置保存动画的最新状态50
anima.fillMode=kCAFillModeForwards;

//2.添加核心动画到layer
[self.myLayer addAnimation:anima forKey:nil];
byValue和toValue的区别,前者是在当前的位置上增加多少,后者是到指定的位置。

在上面的代码中加上anima.delegate = self;即可
使用代理监听动画的执行过程(delegate)

//开始执行动画时调用
-(void)animationDidStart:(CAAnimation *)anim
{

NSLog(@"开始执行动画");

}

//动画执行完毕后调用
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{

//动画执行完毕,打印执行完毕后的position值
NSString *str=NSStringFromCGPoint(self.myLayer.position);
NSLog(@"执行后:%@",str);

}


三、缩放动画

只需要修改以下几点即可

//1.1告诉系统要执行什么样的动画
anima.keyPath=@"bounds";

//设置通过动画,将layer从多大缩放到多大
anima.fromValue=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
anima.toValue=[NSValue valueWithCGPoint:CGPointMake(200, 300)];
//同样也可以直接食用byValue直接从当前大小缩放到指定大小


[b]四、旋转动画[/b]
[b][b]需要修改以下几点即可[/b][/b]
anima.keyPath = @"transform"; //旋转
//1.2修改属性,执行动画(第一个参数为旋转的角度,后面三个分别是些x,y,z)
anima.byValue=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  缩放 旋转 平移