Serialization 按顺序组合多个动画
我读到了有关猫的交易,然后想这可能有助于解决我的问题 这是我不想做的: 我在同一层中有3个动画,它们都有自己的持续时间。我使用带有CGMutablePathRef的CAKeyframeAnimation创建动画 比如说:Serialization 按顺序组合多个动画,serialization,caanimation,cgpath,catransaction,Serialization,Caanimation,Cgpath,Catransaction,我读到了有关猫的交易,然后想这可能有助于解决我的问题 这是我不想做的: 我在同一层中有3个动画,它们都有自己的持续时间。我使用带有CGMutablePathRef的CAKeyframeAnimation创建动画 比如说: 动画1->持续时间5s 动画2->3s 动画3->10s 现在我想按顺序序列化它们。我尝试使用CAAnimationGroup,但动画同时运行。 我读到有关CATransaction的报道,这是一个可能的解决方案吗?你能给我举个小例子吗 谢谢你的帮助 如果序列化是指在前一个
- 动画1->持续时间5s
- 动画2->3s
- 动画3->10s
谢谢你的帮助 如果序列化是指在前一个动画完成后启动每个动画,请使用
beginTime
属性(在CAMediaTiming
协议中定义)。注意,它的文档有点误导。下面是一个例子:
anim2.beginTime = anim1.beginTime + anim1.duration;
anim3.beginTime = anim2.beginTime + anim2.duration;
如果您确定要对层执行此操作,则可以尝试以下操作 在CATTransactions中使用完成块
-(void)animateThreeAnimationsOnLayer:(CALayer*)layer animation:(CABasicAnimation*)firstOne animation:(CABasicAnimation*)secondOne animation:(CABasicAnimation*)thirdOne{
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[CATransaction begin];
[CATransaction setCompletionBlock:^{
//If any thing on completion of all animations
}];
[layer addAnimation:thirdOne forKey:@"thirdAnimation"];
[CATransaction commit];
}];
[layer addAnimation:secondOne forKey:@"secondAnimation"];
[CATransaction commit];
}];
[layer addAnimation:firstOne forKey:@"firstAnimation"];
[CATransaction commit];
}
另一种方法是应用延迟来开始动画。
-(void)animateThreeAnimation:(CALayer*)layer animation:(CABasicAnimation*)firstOne animation:(CABasicAnimation*)secondOne animation:(CABasicAnimation*)thirdOne{
firstOne.beginTime=0.0;
secondOne.beginTime=firstOne.duration;
thirdOne.beginTime=firstOne.duration+secondOne.duration;
[layer addAnimation:firstOne forKey:@"firstAnim"];
[layer addAnimation:secondOne forKey:@"secondAnim"];
[layer addAnimation:thirdOne forKey:@"thirdAnim"];
}
如果要使用UIVIew动画
//if View is applicable in your requirement then you can look this one;
-(void)animateThreeAnimationOnView{
[UIView animateWithDuration:2.0 animations:^{
//first Animation
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 animations:^{
//Second Animation
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 animations:^{
//Third Animation
}];
}];
}];
}