【问题标题】:How to run a CABasicAnimation in a thread如何在线程中运行 CABasicAnimation
【发布时间】:2011-12-25 15:45:41
【问题描述】:
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:只有在整个循环结束后才会被调用。

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

任何机构可以帮助我吗?

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

【问题讨论】:

  • 你不应该在主线程上运行动画吗?

标签: ios multithreading cabasicanimation


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2021-10-24
    • 2014-09-27
    相关资源
    最近更新 更多