Reputation: 2374
I'm trying to create a little glow-animation with Core Animation. Animation works fine so far. Problem is, the animation is used in a table cell. When the animation is added to a layer that is currently in a cell that is not yet visible (without scrolling), the animation is not started somehow? Seems as if CoreAnimation won't animate layers that are not currently visible?
My code is:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[animation setFromValue:[NSNumber numberWithFloat:0.0]];
[animation setToValue:[NSNumber numberWithFloat:1.0]];
[animation setDuration:self.currentBlinkFrequency];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[animation setAutoreverses:YES];
[animation setRepeatCount:HUGE_VALF];
[[self.signalImage layer] addAnimation:animation forKey:@"opacity"];
Upvotes: 1
Views: 1784
Reputation: 2374
Okay found a workaround. I used UIView animation methods instead. Because my animation speed can be changed/switched off during animation I needed to use the following code to avoid kicking of multiple animations on the same view.
This code triggeres the animation :
if (self.currentBlinkFrequency == 0) {
self.shouldContinueBlinking = FALSE;
self.animationIsRunning = FALSE;
} else {
self.shouldContinueBlinking = TRUE;
if (self.animationIsRunning == FALSE) {
self.animationIsRunning = TRUE;
[self blinkAnimation:@"blink" finished:YES target:self.signalImage];
}
}
The invoked anomation code for the "blinkAnimation"-method is borrowed from another post in stackoverflow here
- (void)blinkAnimation:(NSString *)animationId finished:(BOOL)finished target:(UIView *)target
{
if (self.shouldContinueBlinking) {
[UIView beginAnimations:animationId context:target];
[UIView setAnimationDuration:self.currentBlinkFrequency];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(blinkAnimation:finished:target:)];
if ([target alpha] == 1.0f)
[target setAlpha:0.0f];
else
[target setAlpha:1.0f];
[UIView commitAnimations];
}
}
Upvotes: 1