For some context, I recommend reading this:
Very relevant question: "From View Controller" disappears using UIViewControllerContextTransitioning Very relev
Why are you setting shouldRemovePresentersView
to YES
if what you want is that the fromView remains visible?
I had the same problem as you, as in my custom 3d presentation the parent view controller was removed as soon as the transition was completed.
The solution there is to change the modalPresentationStyle
to UIModalPresentationOverCurrentContext
This will specifically prohibit the system to remove the owner viewController when the transition ends.
Still my 3D transition suffered from animation issues, when using this approach.
Si I ended up using a UIModalPresentationCustom
modalPresentationStyle
which solved almost all my issues, with the exception that the new view controller (which was a UINavigationController) would not move down when the in-call status bar would appear.
To solve this, I ended up changing the modalPresentationStyle
back to UIModalPresentationFullScreen
after the transition had been completed.
Here is my code that shows the new viewController with the custom presentation:
//show Login Screen
LoginViewController *viewController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
UINavigationController *loginNavController = [[UINavigationController alloc] initWithRootViewController:viewController];
loginNavController.interactivePopGestureRecognizer.enabled = YES;
loginNavController.transitioningDelegate = self.customTransitionDelegate;
loginNavController.modalPresentationStyle = UIModalPresentationCustom;
[navigationController presentViewController:loginNavController animated:YES
completion:^{
//important, else status bar is not moving entire screen down....
loginNavController.modalPresentationStyle = UIModalPresentationFullScreen;
}
];
Also very important is that you must NOT add the old view to the containerView
when you run your dismissal animation
So if the animation is the presenting, add your toView
to the containerView
UIView* inView = [transitionContext containerView];
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
.....
......
[inView insertSubview:toViewController.view aboveSubview:fromViewController.view];
But on the dismissal presentation DO NOT ADD the view to the containerView
as it is still showing (since we specifically asked the system NOT to remove it), but simply animate between the two views.
I'm adding another answer, as my response is too long to fit in a comment.
First of all the viewForKey
is available in iOS8, so unless you are targeting iOS8 only (why?) you should not use it, or use it after checking that the UIViewControllerContextTransitioning
responds to that selector and use the viewControllerForKey
for iOS7.
With that being said, it seems to me that this is a bug and I explain my self:
If you look at the UIPresentationController
header file, you will see that it says
// Indicate whether the view controller's view we are transitioning from will be removed from the window in the end of the
// presentation transition
// (Default: YES)
- (BOOL)shouldRemovePresentersView;
So as you see the default is YES, so this should only overriden when you specifically want to say NO.
However, you are right, without this being set explicitly to YES, the viewForKey
for the UITransitionContextFromViewControllerKey
remains nil.
I think you should fill in a bug report for this and for now use the viewControllerForKey
which is fine to be used (nothing wrong with this) as it's not deprecated and works in both OS versions without a problem.
And the reason this is most likely a bug is that the viewForKey
should return a view for theUITransitionContextFromViewControllerKey
when the shouldRemovePresentersView
is explicitly set to NO and not YES.
My 2 cents