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

Commit 2564bfd

Browse files
authored
Add support for transitions with custom presented views. (#55)
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.
1 parent 588b63d commit 2564bfd

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/private/MDMViewControllerTransitionCoordinator.m

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -313,35 +313,43 @@ - (void)initiateTransition {
313313
_root.transitionContext = _transitionContext;
314314

315315
UIViewController *from = [_transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
316-
if (from) {
316+
UIView *fromView = [_transitionContext viewForKey:UITransitionContextFromViewKey];
317+
if (fromView == nil) {
318+
fromView = from.view;
319+
}
320+
if (fromView != nil && fromView == from.view) {
317321
CGRect finalFrame = [_transitionContext finalFrameForViewController:from];
318322
if (!CGRectIsEmpty(finalFrame)) {
319-
from.view.frame = finalFrame;
323+
fromView.frame = finalFrame;
320324
}
321325
}
322326

323327
UIViewController *to = [_transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
324-
if (to) {
328+
UIView *toView = [_transitionContext viewForKey:UITransitionContextToViewKey];
329+
if (toView == nil) {
330+
toView = to.view;
331+
}
332+
if (toView != nil && toView == to.view) {
325333
CGRect finalFrame = [_transitionContext finalFrameForViewController:to];
326334
if (!CGRectIsEmpty(finalFrame)) {
327-
to.view.frame = finalFrame;
335+
toView.frame = finalFrame;
328336
}
329337

330-
switch (_direction) {
331-
case MDMTransitionDirectionForward:
332-
[_transitionContext.containerView addSubview:to.view];
333-
break;
338+
if (toView.superview == nil) {
339+
switch (_direction) {
340+
case MDMTransitionDirectionForward:
341+
[_transitionContext.containerView addSubview:toView];
342+
break;
334343

335-
case MDMTransitionDirectionBackward:
336-
if (!to.view.superview) {
337-
[_transitionContext.containerView insertSubview:to.view atIndex:0];
338-
}
339-
break;
344+
case MDMTransitionDirectionBackward:
345+
[_transitionContext.containerView insertSubview:toView atIndex:0];
346+
break;
347+
}
340348
}
341-
342-
[to.view layoutIfNeeded];
343349
}
344350

351+
[toView layoutIfNeeded];
352+
345353
[_root attemptFallback];
346354
[self anticipateOnlyExplicitAnimations];
347355

0 commit comments

Comments
 (0)