I am trying to implement some custom transitions on the iPad but I am getting some issues. Since the x, y coordinates do not always start on the upper left corner in the containerView of the transitionContext when the device is rotated I wrote the following methods
- (CGRect)rectForPresentedStateStart:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    
    switch (fromViewController.interfaceOrientation)
    {
        case UIInterfaceOrientationLandscapeRight:
            return CGRectMake(0, containerView.bounds.size.height,
                              containerView.bounds.size.width, containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationLandscapeLeft:
            return CGRectMake(0, - containerView.bounds.size.height * 2 / 3,
                              containerView.bounds.size.height, containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationPortraitUpsideDown:
            return CGRectMake(- containerView.bounds.size.width * 2 / 3, 0,
                              containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
        case UIInterfaceOrientationPortrait:
            return CGRectMake(containerView.bounds.size.width, 0,
                              containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
        default:
            return CGRectZero;
    }
}
- (CGRect)rectForPresentedStateEnd:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];
    
    switch (toViewController.interfaceOrientation)
    {
        case UIInterfaceOrientationLandscapeRight:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, - containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationLandscapeLeft:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationPortraitUpsideDown:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], containerView.bounds.size.width * 2 / 3, 0);
        case UIInterfaceOrientationPortrait:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], - containerView.bounds.size.width * 2 / 3, 0);
        default:
            return CGRectZero;
    }
}
On portrait mode and upside down everything seems to work fine. The issue is on landscape.
When the devices orientation is UIInterfaceOrientationLandscapeLeft the view disappears for a second just before the transition starts.
When the devices orientation is UIInterfaceOrientationLandscapeRight I get the following issue: The navigation bar is smaller and turns to normal when the transition ends like in the pictures

Issue with navigation bar when transition occurs

After transition is completed
I am not sure if these are bugs from apple or if I am doing something wrong and if so how can I fix the issues?
It is definitely an apple bug. For presenting the animation I am using something like this:
if (self.presenting) {
        toViewController.view.frame = [self rectForPresentedStateStart:transitionContext];
        [transitionContext.containerView addSubview:toViewController.view];
        [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
            fromViewController.view.frame = [self rectForDismissedState:transitionContext];
            toViewController.view.frame = [self rectForPresentedStateEnd:transitionContext];
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];    
}
The problem with the navigation controller is fixed if I add the view (            [transitionContext.containerView addSubview:toViewController.view];
) after the animateWithDuration method. Still cannot figure out why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With