title: CABasicAnimation only works with layers created in the same method
body: <p>I need to animate different CATextLayers depending on some conditions. This is why I wrote a method that accepts the layer and animates it. Here it is:</p>
  
  <pre><code>- (void) animateText:(CATextLayer*) text withColor: (CGColorRef) color andDuration: (NSTimeInterval) duration
  {
      CABasicAnimation *colorAnimation = [CABasicAnimation
                                          animationWithKeyPath:@"foregroundColor"];
      colorAnimation.duration = duration;
      colorAnimation.fillMode = kCAFillModeForwards;
      colorAnimation.removedOnCompletion = NO;
      colorAnimation.fromValue = (id)[UIColor redColor].CGColor;
      colorAnimation.toValue = (id)[UIColor blackColor].CGColor;
      colorAnimation.timingFunction = [CAMediaTimingFunction
                                       functionWithName:kCAMediaTimingFunctionLinear];
      [text addAnimation:colorAnimation
                       forKey:@"colorAnimation"];
  </code></pre>
  
  <p>"text" is a CATextLayer created, initialized and added to sublayers in some other method. 
  The problem is this code does not make the "text" layer animate.</p>
  
  <p>(Please, don't pay attention that the method receives the color. I have temporarily put red and black for testing.)</p>
  
  <p>I started testing. If I create a layer within this method and then try to animate this newly created method, it works ok.
  If I copy-paste the code to the method where all layers are created and try to animate one of them - it works fine too.</p>
  
  <p>But I need to animate different layers at different moments, so I see this function as essential.</p>
  
  <p>Please, explain me what I am doing wrong.
  Thank you in advance.</p>
  
  <p>UPDATED:
  Here's how the layers are created and placed onto UIView</p>
  
  <pre><code>//creating 110 text layers
  
      CGFloat leftPoint = 0;
      CGFloat topPoint = 0;
  
      for (int i=0; i&lt;11; ++i)
      {
          for (int j=0; j&lt;10; ++j)
          {
              CATextLayer *label = [[CATextLayer alloc] init];
              [label setString:[_labels objectAtIndex:j+(i*10)]];  // _labels contains letters to display
              [label setFrame:CGRectMake(leftPoint, topPoint, _labelWidth, _labelHeight)]; // _labelWidth and _labelHeight are valid numbers
              [label setAlignmentMode:kCAAlignmentCenter];
              [label setForegroundColor:_textColor];   // _textColor is a CGColorRef type
              [label setFont:(__bridge CFTypeRef)(_font.fontName)]; // font is UIFont type
              [label setFontSize:[_font pointSize]];
  
              [_textViews addObject:label];    // saving to internal array variable
              [[self layer] addSublayer:label];
  
              leftPoint += _labelWidth;
          }
          leftPoint = 0;
          topPoint += _labelHeight;
      }
  </code></pre>
  
  <p>If I place a code like this in the same method where I do animating, it works.
  And it stops working when I pass the layer in the method like this:</p>
  
  <pre><code>for (int i = 0; i&lt;labelsToHighlight.count; ++i) // labelsToHighlight is an array containing indexes of the CATextLayers which I need to animate
          {
              NSUInteger index = [[labelsToHighlight objectAtIndex:i] intValue];
             [self animateText:[_textViews objectAtIndex:index] withColor: _highlightedTextColor andDuration:_redrawAnimationDuration];
          }
  </code></pre>