CATransaction CompletionBlock立即射击

时间:2013-03-18 22:44:02

标签: iphone ios caanimation catextlayer catransaction

我有这段代码在我的其他项目中完美运行,我在循环中实现了从黑到白闪烁文本的“频闪”效果。当我将其复制并粘贴到我的另一个项目中时,CompletionBlock会立即触发,忽略动画持续时间。可能是什么原因?

- (void)animateTextFlashingWhite
{
    [CATransaction begin];
    [CATransaction setCompletionBlock:^{
        [self animateTextFlashingBlack];
        NSLog(@"finished white");
    }];
    [CATransaction setValue:[NSNumber numberWithFloat:0.7f] forKey:kCATransactionAnimationDuration];
    self.myStrobeLabel.textColor = [UIColor whiteColor];
    [CATransaction commit];
}

- (void)animateTextFlashingBlack
{
    [CATransaction begin];
    [CATransaction setCompletionBlock:^{
        [self animateTextFlashingWhite];
        NSLog(@"finished black");
    }];
    [CATransaction setValue:[NSNumber numberWithFloat:0.7f] forKey:kCATransactionAnimationDuration];
    self.myStrobeLabel.textColor = [UIColor blackColor];
    [CATransaction commit];
}

1 个答案:

答案 0 :(得分:2)

我认为textColor不具有动画效果。

如果您只是想要交叉渐变,可以通过在标签上添加CATransition对象来实现此目的。

[self.myStrobeLabel.layer addAnimation:[CATransition animation] forkey:@"transition"];
self.myStrobeLabel.textColor = [UIColor blackColor];