您的位置:首页 > 其它

Core Anmation之CAKeyframeAnimation

2016-10-26 14:04 197 查看
转载自:http://www.jianshu.com/p/f20cf057ba47

Core Anmation之CAKeyframeAnimation

关键帧动画也是CAPropertyAnimation的子类

与CABasicAnimation的区别

CABasicAnimation只能从一个数值(fromValue)变到另一个数值(toValue)
CAKeyframeAnimation会使用一个NSArray保存这些数值
CABasicAnimation可以看作只有两个关键帧的CAKeyframeAnimation
属性说明
values:NSArray对象,里面的元素称为”关键帧“,动画对象会在指定的时间内,依次显示values数组中的每一个关键帧
path:可以设置一个
CGPathRef
CGMutabelPathRef
,让图层按照路径轨迹移动,path只对
CALayer
anchorPoint
position
起作用,
如果设置了path,那么values将被忽略

keyTimes:可以为对应的关键帧指定对一个你的时间点,其取值范围为0到1.0,keyTimes中的每一个时间值都对应values中的每一帧。如果没有设置keyTimes,各个关键帧的时间是平分的
// 设置values**********************
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

// 设置动画属性
anim.keyPath = @"position";

NSValue *v1 = [NSValue valueWithCGPoint:CGPointZero];

NSValue *v2 = [NSValue valueWithCGPoint:CGPointMake(160, 160)];

NSValue *v3 = [NSValue valueWithCGPoint:CGPointMake(270, 0)];

anim.values = @[v1,v2,v3];

anim.duration = 2;

[_redView.layer addAnimation:anim forKey:nil];

//设置path************************
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

// 设置动画属性
anim.keyPath = @"position";

UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];

anim.path = path.CGPath;

anim.duration = 0.25;

// 取消反弹
anim.removedOnCompletion = NO;

anim.fillMode = kCAFillModeForwards;

anim.repeatCount = MAXFLOAT;

[_redView.layer addAnimation:anim forKey:nil]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息