CAAnimationGroup
CAAnimationGroup——?jiǎng)赢?huà)組
- 動(dòng)畫(huà)組骇吭,是CAAnimation的子類尺棋,可以保存一組動(dòng)畫(huà)對(duì)象,將CAAnimationGroup對(duì)象加入層后绵跷,組中所有動(dòng)畫(huà)對(duì)象可以同時(shí)并發(fā)運(yùn)行
- 屬性說(shuō)明:
- animations:用來(lái)保存一組動(dòng)畫(huà)對(duì)象的NSArray
- 默認(rèn)情況下,一組動(dòng)畫(huà)對(duì)象是同時(shí)運(yùn)行的成福,也可以通過(guò)設(shè)置動(dòng)畫(huà)對(duì)象的beginTime屬性來(lái)更改動(dòng)畫(huà)的開(kāi)始時(shí)間
CAAnimationGroup——?jiǎng)赢?huà)組簡(jiǎn)單實(shí)用
// 平移
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"position";
anim.toValue = [NSValue valueWithCGPoint:CGPointMake(arc4random_uniform(300), arc4random_uniform(500))];
// 縮放
CABasicAnimation *anim1 = [CABasicAnimation animation];
anim1.keyPath = @"transform.scale";
anim1.toValue = @0.5;
// 旋轉(zhuǎn)
CABasicAnimation *anim2 = [CABasicAnimation animation];
anim2.keyPath = @"transform.rotation";
anim2.toValue = @(M_PI);
##核心代碼
// 動(dòng)畫(huà)組
CAAnimationGroup *group = [CAAnimationGroup animation];
// 設(shè)置動(dòng)畫(huà)時(shí)長(zhǎng)
group.duration = 2;
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
// 給動(dòng)畫(huà)組添加動(dòng)畫(huà)
group.animations = @[anim,anim1,anim2];
[_blueView.layer addAnimation:group forKey:nil];