如果您确定要使用图层执行此操作,那么您可以尝试如下
在 CATransactions 中使用完成块
-(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 Animation
//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
}];
}];
}];
}