UIViewControllerContext initalFrameForViewController & finalFrameForViewController show 0 for all values

1k Views Asked by At

I'm implementing my own custom UIViewController transition and when I output to the debugger the frame of the TO View Controller, I receive {{0, 0}, {0, 0}} for both initial and final frame. I thought that method on the context is supposed to show the expected frame after the transition for final, and the initial frame before the transition.

Is this how it is supposed to work?

-(void)startInteractiveTransition:(id<UIViewControllerContextTransitioning>)transitionContext{

    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    CGRect initialToFrame = [transitionContext initialFrameForViewController:toVC];
    CGRect finalToFrame = [transitionContext finalFrameForViewController:toVC];
    NSLog(@"initialToFrame: %@, finalToFrame: %@", NSStringFromCGRect(initialToFrame), NSStringFromCGRect(finalToFrame));
}

Debugger is showing: initialToFrame: {{0, 0}, {0, 0}}, finalToFrame: {{0, 0}, {0, 0}}


Additionally, the Debugger is also showing the following warning. Does this contribute in anyway to the error?

Presenting view controllers on detached view controllers is discouraged

1

There are 1 best solutions below

1
On

First thing you should know is that there are roughly two kinds of custom transitions: full and non-fullscreen and that asking for the final frame for toVC.vew in a non-fullscreen transition just doesn't make sense.

In the case where you don't set modalPresentationStyle or set it explicitly to UIModalPresentationFullScreen (this is the default value) UIKit know that toVC.view will cover the entire screen, so -finalFrameForViewController:toVC will return the correct frame: the main screen frame.

By using modalPresentationStyle = UIModalPresentationCustom you're specifying that the transition should be non-fullscreen, that's it: toVC.view will cover partially fromVC.view (and hence fromCV.view will be kept in the hierarchy), where toVC.view will cover fromVC.view is your decision, that's why -finalFrameForViewController: returns CGRectZero.

What that CGRectZero is telling you is: "Hey mate, leave alone, put that view wherever you want".

Check this presentations out for more information: http://es.slideshare.net/Split82/custom-uiviewcontroller-transitions

Hope this helps.