title: Animation issue in iphone sdk
body: <p>In my app, i use sprite sheet image for displaying animation. I make a png image for that which contain 33 images inside.</p>
  
  <p>But it sometimes displaying very fast and some times displaying good animation.</p>
  
  <p>I don't know why this happen?
  <em>I think it may be the issue of threading.</em>
  <strong>My code is as follow</strong></p>
  
  <pre><code>-(void)correctanswer
  {
  [self setImage];
  }
  
  -(void) setImage
  
  {
      CGAffineTransform rotate = CGAffineTransformMakeRotation( 1.0 / 180.0 * -3.30 );
      [imgv setTransform:rotate];
      layer=[[RMMSpriteLayer alloc]init];
      layer = [RMMSpriteLayer layer];
  
      CGImageRef img1;
      CGSize size;
      img1 = [[UIImage imageNamed:@"newflash.png"] CGImage];
  
  
      size = CGSizeMake(640,1136);
  
      if ([APPDELEGATE isPad]) {
           [imganimation setFrame: CGRectMake(0,0,768,1024)];
      }
      else
      {
           [imganimation setFrame: CGRectMake(0,0,320,480)];
      }
  
      [layer setContents:(id)(img1)];
  
      CGSize normalizedSize = CGSizeMake( size.width/CGImageGetWidth(img1), size.height/CGImageGetHeight(img1) );
      layer.frame = CGRectMake(0,0,320,568);
      if ([APPDELEGATE isPad]) {
          [layer setFrame: CGRectMake(0,0,768,1024)];
      }
      else
      {
         // [layer setFrame: CGRectMake(0,0,320,568)];
          [layer setFrame:CGRectMake(30, 48, 260, 260)];
      }
      layer.contentsRect = CGRectMake( 0, 0, normalizedSize.width, normalizedSize.height );
  
      [[[self view] layer] addSublayer:layer];
      [layer setHidden:NO];
  
      [[self imganimation] setHidden:NO];
      [self.view bringSubviewToFront:imganimation];
  
  
      CGImageRelease(img1);
      [self simulateMemoryWarning];
      [self animationFlush];
  
    }
  
  - (void)animationFlush {
  
  
      [imganimation setHidden:NO];
      [self.view bringSubviewToFront:imganimation];
      CABasicAnimation *anim=[[CABasicAnimation alloc]init];
  //    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];
     anim = [CABasicAnimation animationWithKeyPath:@"sampleIndex"];
  
      anim.fromValue = [NSNumber numberWithInt:1]; // initial frame
      anim.toValue = [NSNumber numberWithInt:33]; // last frame + 1
      //anim.toValue = [NSNumber numberWithInt:];
      anim.duration = 20.0; // from the first frame to the 6th one in 1 second
      anim.repeatCount = 0; // just keep repeating it
      anim.autoreverses = NO; // do 1, 2, 3, 4, 5, 4, 3, 2
      [self remove];
  
      [layer addAnimation:anim forKey:nil];
  
      //[layer release];
  }
  </code></pre>