title: UIView removeFromSuperview inside animation PROPERLY
body: <p>Now, this question have partially been asking alot, but none actually considering how (or when) the messages <code>-viewWillDisappear</code> &amp; <code>-viewDidDisappear</code> are being sent. Almost every example use the following design:</p>
  
  <pre><code>[UIView animateWithDuration:0.5
      delay:1.0
      options: UIViewAnimationCurveEaseOut
      animations:^{
          yourView.alpha = 0;
      }completion:^(BOOL finished){
          [yourView removeFromSuperview]; // Called on complete
      }];
  </code></pre>
  
  <p>The problem with this is that these messages will both be sent when de animation ends! 
  Now, <code>-addSubview</code> can be animated (if put inside the animations-block) which will send the corresponding messages (<code>-viewWillAppear</code> &amp; <code>-viewDidAppear</code>) with correct timedifference. So naturally one would place <code>-removeFromSuperview</code> inside the animations-block. This WILL send the messages correctly, but the view is actually removed instantly making the animation... Well, it won't animate because nothing is left to animate!</p>
  
  <p>Is this intentional from apple and if so, why? How do you do it correctly?</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit.</strong></p>
  
  <p>Just to clearify what I'm doing:
  I got a custom segue, vertically animating a Child-ViewController down from top which works as expected with the following code:</p>
  
  <pre><code>    -(void)perform{
          UIViewController *srcVC = (UIViewController *) self.sourceViewController;
          UIViewController *destVC = (UIViewController *) self.destinationViewController;
  
          destVC.view.transform = CGAffineTransformMakeTranslation(0.0f, -destVC.view.frame.size.height);
          [srcVC addChildViewController:destVC];
          [UIView animateWithDuration:0.5f
                           animations:^{
                               destVC.view.transform = CGAffineTransformMakeTranslation(0.0f, 0.0f);
                               [srcVC.view addSubview:destVC.view];
                           }
                           completion:^(BOOL finished){
                               [destVC didMoveToParentViewController:srcVC];
                           }];
      }
  </code></pre>
  
  <p>Here it will happen in the following order (thanks to <code>-addSubview</code> being inside the animations-block):</p>
  
  <ol>
  <li>Add childView (will automatically invoke <code>-willMoveToParentViewController</code>)</li>
  <li><code>-addSubview</code> will invoke <code>-viewWillAppear</code></li>
  <li>When the animation finishes, <code>-addSubview</code> will invoke <code>-viewDidAppear</code></li>
  <li>Manually invoke <code>-didMoveToParentViewController</code> inside the completion-block</li>
  </ol>
  
  <p>Above is the exact expected behavior (just like the built-in transitions behave).</p>
  
  <p>With the following code to do the above segue but backwards (with an unwindSegue):</p>
  
  <pre><code>-(void)perform{
      UIViewController *srcVC = (UIViewController *) self.sourceViewController;
  
      srcVC.view.transform = CGAffineTransformMakeTranslation(0.0f, 0.0f);
      [srcVC willMoveToParentViewController:nil];
      [UIView animateWithDuration:5.5f
                       animations:^{
                           srcVC.view.transform = CGAffineTransformMakeTranslation(0.0f, -srcVC.view.frame.size.height);
                       }
                       completion:^(BOOL finished){
                           [srcVC.view removeFromSuperview]; // This can be done inside the animations-block, but will actually remove the view at the same time ´-viewWillDisappear´ is invoked, making no sense!
                           [srcVC removeFromParentViewController];
                       }];
  }
  </code></pre>
  
  <p>the flow will be like this:</p>
  
  <ol>
  <li>Manually invoke <code>-willMoveToParentView:nil</code> to notify that it will be removed</li>
  <li>When the animation finishes, both <code>-viewWillDisappear</code> &amp; <code>-viewDidDisappear</code> will be invoked simultaneously (wrong!) and <code>-removeFromParentViewController</code> will automatically invoke <code>-didMoveToParentViewController:nil</code>.</li>
  </ol>
  
  <p>And if I now move <code>-removeFromSuperview</code> in to the animations-block, the events will be sent correctly but the view is removed when the animation starts instead of when the animation finishes (this is the part that makes no sense, following how <code>-addSubview</code> behaves).</p>