Reputation: 4675
I have this piece of code that works perfectly in one of my other projects where I am achieving a 'strobe' effect of text flashing from black to white on a loop. When I copied and pasted it into another one of my projects, the CompletionBlock fires immediately, ignoring the animation duration. What could be the reason?
- (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];
}
Upvotes: 1
Views: 1441
Reputation: 185663
I don't think textColor
is animatable.
If you simply want a crossfade, you can accomplish this by adding a CATransition
object to the label.
[self.myStrobeLabel.layer addAnimation:[CATransition animation] forkey:@"transition"];
self.myStrobeLabel.textColor = [UIColor blackColor];
Upvotes: 2