title: UIImageview Animation Starts using for-in loop and animation delays
body: <p>I need to animate an UIimageview and when i start animation it happens after long time and i found that memory is leaked somewhere at the time of continuous animation for various image views. All I need to do is i have n number of UIviews in scroll view and each view have an custom button. when that button is selected an animation happens and if animation is in process if the user taps on button that animation will continue and it dont need to start again</p>
  
  <p>here is my code</p>
  
  <pre><code> for (int i=0; i&lt;AlphabetArray.count; i++) {
  
      UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 200)];
      view.backgroundColor=[UIColor grayColor];
      view.tag=i+1;
      [self.scrollView addSubview:view];
       UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(200, 50, 400, 400)];
  
  
      [image setImage:[[animationArray objectAtIndex:i]objectAtIndex:0]];
      image.tag=i+1;
      [view addSubview:image];
  
      UIButton *animatebutton=[[UIButton alloc]initWithFrame:CGRectMake(200, 50, 336, 310)];
      animatebutton.tag=i+1;
      [animatebutton addTarget:self action:@selector(makeAnimation:) forControlEvents:UIControlEventTouchUpInside];
      //[animatebutton setImage:[UIImage imageNamed:@"NewtDance_mov_0.png"] forState:UIControlStateNormal];
      [view addSubview:animatebutton];
  }
  
  -(void)makeAnimation:(UIImageView *)sender {
  
  UIView *tagView=(UIView *)[self.view viewWithTag:sender.tag];
  
  
  
  for (UIImageView * imageview in [tagView subviews]) {
  
      NSLog(@"Yes %d",imageview.tag);
  
  
      if ([imageview isKindOfClass:[UIImageView class]]) {
  
          if ([imageview isAnimating]) {
              NSLog(@"Animation Happens");
  
          }
  
          else{
              imageview.animationDuration=3.0;
  
              imageview.animationImages=[animationArray objectAtIndex:sender.tag-1];
              imageview.animationRepeatCount=2;
              imageview.tag=sender.tag;
              [imageview startAnimating];
          }
      }
  
  }
  
  
  
  NSLog(@"OK");
  
  
  }
  </code></pre>
  
  <p>With this code i can achieve what my requirement is about. But the animation starts very late because of for-in loop used</p>