我有一个包含8个NSArray对象的CAShapeLayer。我的目标是在一定的时间内将填充颜色从一个动画变为另一个填充颜色,然后再次调用相同的方法。它似乎几乎奏效,但它的持续时间并没有被考虑在内。这是密码,也许你能帮忙?
[CATransaction begin];
for (int i = 0; i < MAX_NUM_LIGHTS; i++)
{
NSUInteger c = [colorsArray count];
CAShapeLayer *l = (CAShapeLayer*)llayers[i];
// the fill color after the anim is complete
[l setFillColor:((UIColor*)colorsArray[(i+index)%c]).CGColor];
CABasicAnimation *fillColorAnimation = [CABasicAnimation animationWithKeyPath:@"fillColor"];
fillColorAnimation.duration = 2.0f;
fillColorAnimation.toValue = (id)((UIColor*)colorsArray[(i+index)%c]).CGColor;
fillColorAnimation.repeatCount = 0;
fillColorAnimation.autoreverses = FALSE;
[l addAnimation:fillColorAnimation forKey:@"fillColor"];
}
[CATransaction setCompletionBlock:^
{
if (currEffect != LpyEffect_MultiBall) return;
NSUInteger c = [colorsArray count];
int r = (index+1)%c;
[self simMultiBallEffect:r]; // recursive call, new index
}];
[CATransaction commit];
发布于 2014-09-09 22:58:23
+[CATransaction setCompletionBlock:]
的文档显示:
一旦该事务组随后添加的所有动画都完成(或已被删除),即保证调用该完成块对象(在主线程上)。如果在提交当前事务组之前没有添加动画(或者将完成块设置为不同的值),则将立即调用该块。
添加所有动画后,您将设置完成块。在添加任何动画之前,您需要设置它。
https://stackoverflow.com/questions/25753943
复制相似问题