title: Custom transition iOS (Push/Pop)
body: <p>I created a custom zoom-in transition when <strong>pushing</strong> a new viewController, and it used to work perfectly fine. Now I want to create a zoom-out effect when  <strong>popping</strong> the viewController, and even-thought the final state is correct, the animation is wrong since I don't know how to identify if it is pushing or popping and all the methods like <code>isBeingPresented</code> return false and <code>presentedViewController</code> is always nil</p>
  
  <pre><code>-(void)animateTransition:(id&lt;UIViewControllerContextTransitioning&gt;)transitionContext
  {
    self.transitionContext = transitionContext;
  
    UIView *containerView =  [transitionContext containerView];
    UIViewController *fromViewController = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = (UIViewController *) [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
  
    [containerView addSubview:toViewController.view];
  
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.duration = [self transitionDuration:transitionContext];
    scaleAnimation.delegate = self;
    scaleAnimation.removedOnCompletion = YES;
  
    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.duration = [self transitionDuration:transitionContext];
    opacityAnimation.delegate = self;
    opacityAnimation.removedOnCompletion = YES;
  
    if (toViewController.isBeingPresented) {
      scaleAnimation.fromValue = [NSNumber numberWithDouble:0];
      scaleAnimation.toValue = [NSNumber numberWithDouble:1];
  
      opacityAnimation.fromValue = [NSNumber numberWithFloat:1];
      opacityAnimation.toValue = [NSNumber numberWithFloat:0];
    } else {
      scaleAnimation.fromValue = [NSNumber numberWithDouble:1];
      scaleAnimation.toValue = [NSNumber numberWithDouble:0];
  
      opacityAnimation.fromValue = [NSNumber numberWithFloat:0];
      opacityAnimation.toValue = [NSNumber numberWithFloat:1];
    }
  
    [toViewController.view.layer addAnimation:scaleAnimation forKey:nil];
    [fromViewController.view.layer addAnimation:opacityAnimation forKey:nil];
  }
  </code></pre>