CAAnimation 一個(gè)抽象的動(dòng)畫類,可以使用它的子類來實(shí)現(xiàn)動(dòng)畫.
- CAMediaTiming
duration :執(zhí)行完成動(dòng)畫的時(shí)間
beginTime :開始動(dòng)畫的時(shí)間
removedOnCompletion :動(dòng)畫執(zhí)行完畢是否移除動(dòng)畫
fillMode :動(dòng)畫完成后的呈現(xiàn)方式
repeatCount :動(dòng)畫循環(huán)次數(shù)
repeatDuration :動(dòng)畫循環(huán)時(shí)長
timeOffset :時(shí)間的偏移.
speed :速度
autoreverses :執(zhí)行完成后是否歸回原位
屬性動(dòng)畫
- CABasicAnimation : 可以通過設(shè)置一個(gè)關(guān)鍵幀來實(shí)現(xiàn)layer的屬性動(dòng)畫.
fromValue :動(dòng)畫起始值
toValue :動(dòng)畫結(jié)束值
byValue :動(dòng)畫執(zhí)行過程中的插入值(有疊加效果)
1.使用時(shí)要注意這三個(gè)值盡量不要同時(shí)使用,防止沖突.
2.對象類型必須匹配屬性的類型是動(dòng)畫
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"position"];
basic.fromValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
basic.toValue = [NSValue valueWithCGPoint:CGPointMake(300, 300)];
basic.duration = 0.5;
basic.beginTime = CACurrentMediaTime()+1;
basic.fillMode = kCAFillModeForwards;
basic.removedOnCompletion = NO;
[self.basicView.layer addAnimation:basic forKey:@""];
- CAKeyframeAnimation : 可以通過設(shè)置一個(gè)關(guān)鍵幀來實(shí)現(xiàn)layer的屬性動(dòng)畫.
values :keyPath的值變化組
path :可以設(shè)置一個(gè)path,作為運(yùn)動(dòng)路徑
keyTimes :每個(gè)關(guān)鍵幀的時(shí)長
timingFunction
calculationMode :該屬性決定了物體在每個(gè)子路徑下是跳著走還是勻速走
rotationMode :旋轉(zhuǎn)軌道類型
tensionValues
continuityValues
biasValues
CAKeyframeAnimation *keyAnimation = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
keyAnimation.values = @[(id)[UIColor redColor].CGColor, (id)[UIColor yellowColor].CGColor, (id)[UIColor blueColor].CGColor];
keyAnimation.duration = 2;
keyAnimation.keyTimes = @[[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.1],[NSNumber numberWithFloat:1.0]];
keyAnimation.beginTime = CACurrentMediaTime()+1;
keyAnimation.fillMode = kCAFillModeForwards;
keyAnimation.removedOnCompletion = NO;
[self.basicView.layer addAnimation:keyAnimation forKey:@""];