UIViewControllerAnimatedTransitioning con un MPMoviePlayerViewController

Estoy tratando de hacer una animation de presentación personalizada, pero el VC es un MPMoviePlayerViewController . Seguí este tutorial:

Cuando presento el MPMoviePlayerViewController , todo está bien.

Pero cuando lo rechazo, simplemente el método:

  - (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed 

No se llama, ¿qué estoy haciendo mal?

Este es el código:

 - (IBAction)playButtonTouchedIn:(id)sender { NSURL *url = [[NSBundle mainBundle]URLForResource:@"Learn to speak Spanish quickly with funny videos on youtube" withExtension:@"mp4"]; MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; player.transitioningDelegate = self; player.modalTransitionStyle = UIModalPresentationCustom; [player.moviePlayer setShouldAutoplay:NO]; player.moviePlayer.controlStyle = MPMovieControlStyleNone; [self presentViewController:player animated:YES completion:^{ [player.moviePlayer play]; player.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; }]; } 

Los methods UIViewControllerTransitioningDelegate :

 - (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController: (UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { self.presenting = YES; return self; } - (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { self.presenting = NO; return self; } 

El UIViewControllerAnimatedTransitioning Methods

 - (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext { return 0.7; } - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext { UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; if (self.isPresenting) { [fromViewController.view setUserInteractionEnabled:NO]; [transitionContext.containerView addSubview:fromViewController.view]; [transitionContext.containerView addSubview:toViewController.view]; CGRect startFrame = toViewController.view.frame; toViewController.view.frame = (CGRect){CGPointMake(toViewController.view.frame.size.width, 0),startFrame.size}; [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0f usingSpringWithDamping:0.5f initialSpringVelocity:4.0f options:UIViewAnimationOptionCurveEaseOut animations:^{ toViewController.view.frame = startFrame; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; [fromViewController.view setUserInteractionEnabled:YES]; }]; } else{ [toViewController.view setUserInteractionEnabled:YES]; [transitionContext.containerView addSubview:toViewController.view]; [transitionContext.containerView addSubview:fromViewController.view]; CGRect finalFrame = (CGRect){CGPointMake(-fromViewController.view.frame.size.width, 0),fromViewController.view.frame.size}; [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ fromViewController.view.frame = finalFrame; } completion:^(BOOL finished) { [transitionContext completeTransition:YES]; }]; } } 

Lo he intentado con un controller de vista desarrollado por mí y funciona muy bien, así que ¿debería ser MPMoviePlayerViewController ?

La forma en que pude conseguir que se animara correctamente en la modalTransitionStyle fue volver a establecer la transitioningDelegate y modalTransitionStyle justo antes de llamar [presentingViewController dismissViewControllerAnimated:YES];

Entonces, en lugar de solo

 - (IBAction) closePressed:(id)sender { [self.presentingViewController dismissViewControllerAnimated:YES]; } 

Tu harías

 - (IBAction) closePressed:(id)sender { MPCustomModalTransitionDelegate *delegate = [[MPCustomModalTransitionDelegate alloc]init]; self.transitioningDelegate = delegate; self.modalTransitionStyle = UIModalPresentationCustom; [self.presentingViewController dismissViewControllerAnimated:YES]; } 

La diferencia obvia aquí es la adición de una nueva class MPCustomModalTransitionDelegate , que necesitaría para refactorizar fuera de su controller de vista.