Reputation: 2741
I am trying to create custom animation during transition between two uiviewcontrollers. When i am trying to pop a view controller i am getting nil
object in [transitionContext containerView]
. Here is my code for custom transition class
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController * toViewController = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromViewController = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *containerView = [transitionContext containerView];//returns nil
[containerView addSubview:toViewController.view];
[fromViewController.view removeFromSuperview];
[transitionContext completeTransition:YES];
}
I am using similar kind of code while pushing the view controller and its working perfectly. But during pop its creating trouble.
Upvotes: 3
Views: 1393
Reputation:
I was running into this issue myself, and it looks like you need to add your fromViewController
's view to containerView
as well.
As the documentation for the transitionContext
's containerView
method says:
The animator object is responsible for adding the view of the presented view controller...
It's unclear why, but not adding your fromViewController
's view (the "presented view controller" view) to the containerView
results in a working transition the first time, but a nil
containerView
on subsequent transitions.
Upvotes: 1