title: UIView animation change image of button
body: <p>I have <code>UIButton</code> and i want to change is image with animation (change 4 images), i tried this method but it only change to the last image.</p>
  
  <p>what i try to do is to put small image of the <code>UIButton</code> from the currently image.</p>
  
  <pre><code> [UIView beginAnimations:nil context:NULL];
      [UIView setAnimationDuration:2.0];
      [UIView setAnimationDelegate:self];
  
      [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_2.png"] forState:UIControlStateNormal];
      [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_3.png"] forState:UIControlStateNormal];
      [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_2.png"] forState:UIControlStateNormal];
      [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_1.png"] forState:UIControlStateNormal];
  
      [UIView commitAnimations];
  </code></pre>
  
  <h1>Edit</h1>
  
  <pre><code>-(void)animationPlayButton:(NSString*)name{
      if ([name isEqualToString:@"pause"]) {
          [UIView beginAnimations:@"pause1" context:NULL];
      }else if ([name isEqualToString:@"play"]){
          [UIView beginAnimations:@"play1" context:NULL];
      }
  
      [UIView setAnimationDuration:10.0];
      [UIView setAnimationDelay:2.0];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDidStopSelector:@selector(buttonAnimationDidStop:finished:context:)];
  
      if ([name isEqualToString:@"pause"]) {
          [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_2.png"] forState:UIControlStateNormal];
      }else {
          [playBtn setImage:[UIImage imageNamed:@"Control_PLAY_2.png"] forState:UIControlStateNormal];
      }
  
      [UIView commitAnimations];
  }
  
  - (void)buttonAnimationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context{
      if (!animationID) {
          NSLog(@"null");
          return;
      }
      NSLog(@"%@",animationID);
  
      if ([animationID isEqualToString:@"pause1"]) {
          [UIView beginAnimations:@"pause2" context:NULL];
      }else if ([animationID isEqualToString:@"play1"]){
          [UIView beginAnimations:@"play2" context:NULL];
      }else if ([animationID isEqualToString:@"pause2"]) {
          [UIView beginAnimations:@"pause3" context:NULL];
      }else if ([animationID isEqualToString:@"play2"]){
          [UIView beginAnimations:@"play3" context:NULL];
      }else if ([animationID isEqualToString:@"pause3"]) {
          [UIView beginAnimations:NULL context:NULL];
      }else if ([animationID isEqualToString:@"play3"]){
          [UIView beginAnimations:NULL context:NULL];
      }
  
      [UIView setAnimationDuration:10.0];
      [UIView setAnimationDelay:2.0];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDidStopSelector:@selector(buttonAnimationDidStop:finished:context:)];
  
      if ([animationID isEqualToString:@"pause1"]) {
          [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_3.png"] forState:UIControlStateNormal];
      }else if ([animationID isEqualToString:@"play1"]) {
          [playBtn setImage:[UIImage imageNamed:@"Control_PLAY_3.png"] forState:UIControlStateNormal];
      }else if ([animationID isEqualToString:@"pause2"]) {
          [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_2.png"] forState:UIControlStateNormal];
      }else if ([animationID isEqualToString:@"play2"]) {
          [playBtn setImage:[UIImage imageNamed:@"Control_PLAY_2.png"] forState:UIControlStateNormal];
      }else if ([animationID isEqualToString:@"pause3"]) {
          [playBtn setImage:[UIImage imageNamed:@"Control_PAUSE_1.png"] forState:UIControlStateNormal];
      }else if ([animationID isEqualToString:@"play3"]) {
          [playBtn setImage:[UIImage imageNamed:@"Control_PLAY_1.png"] forState:UIControlStateNormal];
      }
  
      [UIView commitAnimations];
  }
  </code></pre>