For some context, I recommend reading this:
Very relevant question: "From View Controller" disappears using UIViewControllerContextTransitioning Very relevant answer: https://stackoverflow.com/a/25901154/751268
I'm trying to implement a custom view controller transition that animates the new view controller to cover half the screen, while simultaneously shrinking the presenting view controller to 90% (centered in the window, underneath the presented view controller).
First, my problem was that viewFromKey:
returned nil
. To solve that, the answer mentioned:
If you want to animate the presenting view controllers's view you should consider using
UIModalPresentationFullscreen
style or continue usingUIModalPresentationCustom
and implement your own subclass ofUIPresentationController
withshouldRemovePresentersView
returning YES.
I did that, and viewFromKey:
doesn't return nil
anymore, but now the presenting view controller disappears completely (which makes sense considering I explicitly say it should by implementing shouldRemovePresentersView
).
I add the presenting view controller's view to the container view, but it still gets removed. Is there anything else I should be doing to get this working?
Here's some relevant code:
UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey
UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
BOOL show = self.isPresentation;
UIView *menuView = show ? toView : fromView;
UIView *backView = show ? fromView : toView;
UIView *containerView = [transitionContext containerView];
[containerView addSubview:backView];
[containerView addSubview:dimmedView];
[containerView addSubview:menuView];
// Adjust transforms, alpha and perform animations
I thought that by returning YES
from shouldRemovePresentersView
and manually adding it to the containerView
, that should fix the issue, but backView
gets removed anyway...