I'm trying to do a custom presentation animation but the VC is an MPMoviePlayerViewController
. I was following this tutorial:
When I present the MPMoviePlayerViewController
, all is right.
But when I dismiss it, simply the method:
- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
is not called, what I'm doing wrong?
This is the code:
- (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;
}];
}
The UIViewControllerTransitioningDelegate
methods:
- (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;
}
The 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];
}];
}
}
I have tried with a view controller developed by me and it works great, so is should be the MPMoviePlayerViewController
?
MPMoviePlayerViewController
was inside of aUINavigationController
? I'm wondering if that has something to do with it. – HeadspringtransitioningDelegate
andmodalPresentationStyle
AGAIN right before it dismisses. That was definitely not expected... – Headspring