我有这段代码在我的其他项目中完美运行,在该项目中,我实现了文本在循环中从黑色闪烁到白色的“频闪”效果。当我将它复制并粘贴到我的另一个项目中时,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];
}