1

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"];    
Chris
  • 2,296
  • 4
  • 27
  • 46
  • Where you add your animations to cell? What behavior you get and what expect to get? If you're using table view cells correctly (i.e. reusing cells properly) then if cell is not visible then it is likely not exists at all... – Vladimir Aug 09 '10 at 10:55
  • I just want to add a glowing animation to an UIImageView in a TableCell. – Chris Aug 09 '10 at 11:24

1 Answers1

1

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];
    }
}
Community
  • 1
  • 1
Chris
  • 2,296
  • 4
  • 27
  • 46