原文http://www.cnblogs.com/iBaby/p/3818445.html
- 簡(jiǎn)單介紹
是CApropertyAnimation的子類,跟CABasicAnimation的區(qū)別是:CABasicAnimation只能從一個(gè)數(shù)值(fromValue)變到另一個(gè)數(shù)值(toValue)攻走,而CAKeyframeAnimation會(huì)使用一個(gè)NSArray保存這些數(shù)值
- 屬性解析:
- values:就是上述的NSArray對(duì)象蚯斯。里面的元素稱為”關(guān)鍵幀”(keyframe)。動(dòng)畫對(duì)象會(huì)在指定的時(shí)間(duration)內(nèi)牢贸,依次顯示values數(shù)組中的每一個(gè)關(guān)鍵幀
- path:可以設(shè)置一個(gè)CGPathRef\CGMutablePathRef,讓層跟著路徑移動(dòng)竹观。path只對(duì)CALayer的anchorPoint和position起作用。如果你設(shè)置了path潜索,那么values將被忽略
- keyTimes:可以為對(duì)應(yīng)的關(guān)鍵幀指定對(duì)應(yīng)的時(shí)間點(diǎn),其取值范圍為0到1.0,keyTimes中的每一個(gè)時(shí)間值都對(duì)應(yīng)values中的每一幀.當(dāng)keyTimes沒有設(shè)置的時(shí)候,各個(gè)關(guān)鍵幀的時(shí)間是平分的
- 說明:CABasicAnimation可看做是最多只有2個(gè)關(guān)鍵幀的CAKeyframeAnimation
- Values方式:
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.keyPath = @"position";
NSValue *value1=[NSValue valueWithCGPoint:CGPointMake(100, 100)];
NSValue *value2=[NSValue valueWithCGPoint:CGPointMake(200, 100)];
NSValue *value3=[NSValue valueWithCGPoint:CGPointMake(200, 200)];
NSValue *value4=[NSValue valueWithCGPoint:CGPointMake(100, 200)];
NSValue *value5=[NSValue valueWithCGPoint:CGPointMake(100, 100)];
animation.values=@[value1,value2,value3,value4,value5]; animation.repeatCount=MAXFLOAT;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.duration = 4.0f;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.delegate=self;
[self.myView.layer addAnimation:animation forKey:nil];
- Path方式:
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.keyPath = @"position";
CGMutablePathRef path=CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, CGRectMake(150, 100, 100, 100));
animation.path=path;
CGPathRelease(path);
animation.repeatCount=MAXFLOAT;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
animation.duration = 4.0f;
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.delegate=self;
[self.myView.layer addAnimation:animation forKey:nil];
- keyPath可以使用的key
- #define angle2Radian(angle) ((angle)/180.0*M_PI)
- transform.rotation.x 圍繞x軸翻轉(zhuǎn) 參數(shù):角度 angle2Radian(4)
transform.rotation.y 圍繞y軸翻轉(zhuǎn) 參數(shù):同上
transform.rotation.z 圍繞z軸翻轉(zhuǎn) 參數(shù):同上
transform.rotation 默認(rèn)圍繞z軸
transform.scale.x x方向縮放 參數(shù):縮放比例 1.5
transform.scale.y y方向縮放 參數(shù):同上
transform.scale.z z方向縮放 參數(shù):同上
transform.scale 所有方向縮放 參數(shù):同上
transform.translation.x x方向移動(dòng) 參數(shù):x軸上的坐標(biāo) 100
transform.translation.y x方向移動(dòng) 參數(shù):y軸上的坐標(biāo)
transform.translation.z x方向移動(dòng) 參數(shù):z軸上的坐標(biāo)
transform.translation 移動(dòng) 參數(shù):移動(dòng)到的點(diǎn) (100臭增,100)
opacity 透明度 參數(shù):透明度 0.5
backgroundColor 背景顏色 參數(shù):顏色 (id)[[UIColor redColor] CGColor]
cornerRadius 圓角 參數(shù):圓角半徑 5
borderWidth 邊框?qū)挾?參數(shù):邊框?qū)挾?5
bounds 大小 參數(shù):CGRect
contents 內(nèi)容 參數(shù):CGImage
contentsRect 可視內(nèi)容 參數(shù):CGRect 值是0~1之間的小數(shù)
hidden 是否隱藏
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius