Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Add support for transitions with custom presented views. (#55)
Browse files Browse the repository at this point in the history
If the transition's presentation controller implements -presentedView, it's possible that viewForKey: will not return the view of either of the fore/back view controllers. This type of behavior is often implemented if the presented view controller's view is being embedded inside of another view.

In order to support this behavior, we must use the viewForKey: API to fetch the desired view. If that view matches the view controller's view, then we can set the view's frame to the view controller's destination frame as we had been doing before. Otherwise, we make no modifications to the view's frame.
  • Loading branch information
jverkoey authored Nov 13, 2017
1 parent 588b63d commit 2564bfd
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/private/MDMViewControllerTransitionCoordinator.m
Original file line number Diff line number Diff line change
Expand Up @@ -313,35 +313,43 @@ - (void)initiateTransition {
_root.transitionContext = _transitionContext;

UIViewController *from = [_transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
if (from) {
UIView *fromView = [_transitionContext viewForKey:UITransitionContextFromViewKey];
if (fromView == nil) {
fromView = from.view;
}
if (fromView != nil && fromView == from.view) {
CGRect finalFrame = [_transitionContext finalFrameForViewController:from];
if (!CGRectIsEmpty(finalFrame)) {
from.view.frame = finalFrame;
fromView.frame = finalFrame;
}
}

UIViewController *to = [_transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
if (to) {
UIView *toView = [_transitionContext viewForKey:UITransitionContextToViewKey];
if (toView == nil) {
toView = to.view;
}
if (toView != nil && toView == to.view) {
CGRect finalFrame = [_transitionContext finalFrameForViewController:to];
if (!CGRectIsEmpty(finalFrame)) {
to.view.frame = finalFrame;
toView.frame = finalFrame;
}

switch (_direction) {
case MDMTransitionDirectionForward:
[_transitionContext.containerView addSubview:to.view];
break;
if (toView.superview == nil) {
switch (_direction) {
case MDMTransitionDirectionForward:
[_transitionContext.containerView addSubview:toView];
break;

case MDMTransitionDirectionBackward:
if (!to.view.superview) {
[_transitionContext.containerView insertSubview:to.view atIndex:0];
}
break;
case MDMTransitionDirectionBackward:
[_transitionContext.containerView insertSubview:toView atIndex:0];
break;
}
}

[to.view layoutIfNeeded];
}

[toView layoutIfNeeded];

[_root attemptFallback];
[self anticipateOnlyExplicitAnimations];

Expand Down

0 comments on commit 2564bfd

Please sign in to comment.