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
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.vewin a non-fullscreen transition just doesn't make sense.In the case where you don't set
modalPresentationStyleor set it explicitly toUIModalPresentationFullScreen(this is the default value) UIKit know thattoVC.viewwill cover the entire screen, so-finalFrameForViewController:toVCwill return the correct frame: the main screen frame.By using
modalPresentationStyle = UIModalPresentationCustomyou're specifying that the transition should be non-fullscreen, that's it:toVC.viewwill cover partiallyfromVC.view(and hencefromCV.viewwill be kept in the hierarchy), wheretoVC.viewwill coverfromVC.viewis your decision, that's why-finalFrameForViewController:returnsCGRectZero.What that
CGRectZerois 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.