I'm trying to make a countdown timer which also changes it's color.
I'm trying to animate the UILabel during the whole countdown, like one long animation. So when the timer is at 60 seconds, the textColor is black, at 30 it would seem gray and at 0, the textColor is white.
The problem I'm having is that the color changes perfectly over time, but that the text of the label isn't changed. It looks like the label is frozen until the color animation stops. After that, the label is counting down normally.
This is the code I'm using:
- (IBAction) startTimerWithButton:(UIButton *) sender {
if (!self.timer) {
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateCounterWithTimer:) userInfo:nil repeats:YES];
[UIView transitionWithView:self.timeLabel duration:(self.timeInterval / 2)
options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent | UIViewAnimationOptionTransitionCrossDissolve)
animations:^{ self.timeLabel.textColor = [UIColor whiteColor]; }
completion:nil];
}
else {
[self.timer invalidate];
self.timer = nil;
}
}
- (void) updateCounterWithTimer:(NSTimer *) theTimer {
if (self.timeInterval > 0) {
self.timeInterval--;
self.timeLabel.text = [NSString stringWithFormat:@"%02d", (int) self.timeInterval];
}
}
Am I missing an UIViewAnimationOption here? Is there a way to combine those animations (changing text of the UILabel and changing of the textColor)?