CABasicAnimation
- 父類是CAPropertyAnimation
CABasicAnimation——基本動(dòng)畫
基本動(dòng)畫,是CAPropertyAnimation的子類
-
屬性說明:
- fromValue:keyPath相應(yīng)屬性的初始值
- toValue:keyPath相應(yīng)屬性的結(jié)束值
-
動(dòng)畫過程說明:
- 隨著動(dòng)畫的進(jìn)行,在長(zhǎng)度為duration的持續(xù)時(shí)間內(nèi),keyPath相應(yīng)屬性的值從fromValue漸漸地變?yōu)閠oValue
- keyPath內(nèi)容是CALayer的可動(dòng)畫Animatable屬性
- 如果fillMode=kCAFillModeForwards同時(shí)removedOnComletion=NO,那么在動(dòng)畫執(zhí)行完畢后,圖層會(huì)保持顯示動(dòng)畫執(zhí)行后的狀態(tài)。但在實(shí)質(zhì)上,圖層的屬性值還是動(dòng)畫執(zhí)行前的初始值,并沒有真正被改變。
CABasicAnimation實(shí)現(xiàn)形變效果
// 1.創(chuàng)建核心動(dòng)畫
CABasicAnimation *anim = [CABasicAnimation animation];
// 2.描述修改Layer哪個(gè)屬性
anim.keyPath = keyPath(_redView.layer, position);
##核心代碼
// 3.描述修改layer屬性的值
// 動(dòng)畫的起點(diǎn)
// anim.fromValue =
// 動(dòng)畫的終點(diǎn)
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(300, 400)];
// 動(dòng)畫時(shí)長(zhǎng)
anim.duration = 1;
// 取消反彈
// 1.在動(dòng)畫完成的時(shí)候不要給我把動(dòng)畫銷毀
anim.removedOnCompletion = NO;
// 2.動(dòng)畫永遠(yuǎn)保持最新的狀態(tài)
anim.fillMode = kCAFillModeForwards;
##
// 添加核心動(dòng)畫
[_redView.layer addAnimation:anim forKey:nil];
CABasicAnimation實(shí)現(xiàn)縮放-心臟跳動(dòng)效果
// 1.創(chuàng)建動(dòng)畫對(duì)象
CABasicAnimation *anim = [CABasicAnimation animation];
// 2.描述修改layer的屬性
anim.keyPath = keyPath(_imageView.layer, transform);
##核心代碼
// 3.修改layer的值
anim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5, 0.5, 1)];
// 設(shè)置動(dòng)畫執(zhí)行次數(shù)
anim.repeatCount = MAXFLOAT;
//自動(dòng)翻轉(zhuǎn)
anim.autoreveres = YES;
##
// 4.添加到圖層
[_imageView.layer addAnimation:anim forKey:nil];