title: iOS: How to detect when an animation is finished?
body: <p>Is there a method to detect when an animation is finished? I want to call <code>[nav setTitle:navItem]</code> when the animation is finished.</p>
  
  <p>Here below is a snippet of my code. Hope the question is clear enough, so I can get a solution, and preferably an example.</p>
  
  <pre><code>-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
  
  if(event.subtype == UIEventSubtypeMotionShake){
  
  
      NSString *imageUrl = @"";
      NSString *navItem = @"";
  
      int randomNumber = arc4random() % 3;
  
      switch (randomNumber) {
          case 0:
              imageUrl = @"pic1.png";
              navItem = @"txt1";
              break;
          case 1:
              imageUrl = @"pic2.png";
              navItem = @"txt2";
              break;
          case 2:
              imageUrl = @"pic3.png";
              navItem = @"txt3";
              break;
          default:
              break;
      }
  
      animation.animationImages = [NSArray arrayWithObjects:
  
                                   [UIImage imageNamed:@"pic1.png"],
                                   [UIImage imageNamed:@"pic3.png"],
                                   [UIImage imageNamed:@"pic2.png"],
                                   [UIImage imageNamed:@"pic1.png"],
                                   [UIImage imageNamed:@"pic2.png"],
                                   [UIImage imageNamed:@"pic3.png"], 
                                   [UIImage imageNamed:imageUrl],
                                   nil];
  
      UIImage *img = [UIImage imageNamed:imageUrl];
      [imageview setImage:img];
  
      [animation setAnimationRepeatCount:1];
      animation.animationDuration = 1;
      [animation startAnimating]; 
  
      [nav setTitle:navItem]; 
  
  }
  
  }
  </code></pre>