0
for(NSInteger i = 0; i < 10; i++)
{
    ....
    singleThread = [[NSThread alloc] initWithTarget:self selector:@selector(changeLayerBackground) object:nil];
    [singleThread start];
}

函数 changeLayerBackground 像这样:

- (void) changeLayerBackground
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];
    animation.delegate = self;
    ......
    [layer addAnimation:selectionAnimation forKey:@"animation"];
}

我发现animationDidStop:finished:只有在整个循环完成后才调用该函数。

有人对此有任何想法吗?
现在,我认为这是因为动画的委托是自我,即视图控制器。并且动画是由线程调用的,所以委托不起作用。但我不知道如何改变它。我尝试使用线程作为替代,它仍然不起作用。

任何机构都可以帮助我吗?

我的目标是当动画被调用时,循环应该暂停,直到动画完成,然后循环应该继续。直到循环结束。

4

1 回答 1

0

您确定要在线程中运行动画吗?因为它已经在自己的线程中运行。正如文档所说,CoreAnimation 提供

一个抽象动画接口,允许动画在单独的线程上运行,独立于应用程序的运行循环。

也许您只是想链接动画?如果是这样,请查看此线程:链接动画

于 2011-12-26T03:00:42.157 回答