? 最近的項目涉及到動畫的連接,? 需求是? 1-25秒 的一個橫向位移動畫? 在23-25s 的時候隱身,需要完美銜接!? 由于本人很菜所以只想到 定時器? 延時方法 但是 都不完美 , 然后搜索資料的時候發(fā)現(xiàn)了? CAAnimationGroup.?
CAAnimationGroup 可以 把 各個 動畫 銜接在一起
CABasicAnimation*opacityAnimation1 = [CABasicAnimationanimationWithKeyPath:@"opacity"];
opacityAnimation1.fromValue= [NSNumbernumberWithFloat:0.0];
opacityAnimation1.toValue= [NSNumbernumberWithFloat:1.0];
//注意setBeginTime在第幾秒開始動畫duration持續(xù)多久
[opacityAnimation1setBeginTime:0];
opacityAnimation1.duration=1;
CABasicAnimation*animation=[CABasicAnimationanimationWithKeyPath:@"transform.translation.x"];
animation.toValue=[NSValuevalueWithCGRect:CGRectMake(width1 -self.view.frame.size.width,0, width1, height)];
[animationsetBeginTime:0];
animation.duration=25;
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
CABasicAnimation*opacityAnimation = [CABasicAnimationanimationWithKeyPath:@"opacity"];
opacityAnimation.fromValue= [NSNumbernumberWithFloat:1.0];
opacityAnimation.toValue= [NSNumbernumberWithFloat:0.0];
[opacityAnimationsetBeginTime:24];
opacityAnimation.duration=1;
CAAnimationGroup*group = [CAAnimationGroupanimation];
group.duration=25;
group.animations=@[opacityAnimation1,animation,opacityAnimation];
group.removedOnCompletion=NO;
group.repeatCount=100000;
[yun_1.layeraddAnimation:groupforKey:@"group"];