Search code examples
iosxcodeanimationuiviewcontrolleruiviewanimationtransition

UIViewController Custom Transition in iOS8


Does anyone have any ideas this no long does a custom flip animation in iOS8 but does in iOS7.

In iOS8 i just get the view presented with no animation but when that view is dismissed i do get the custom flip transition. Its like it is forgetting to animate when presented but when it is dismissed it remembers.

Any help would be appreciated it is driving me nuts.

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

    UIView *containerView = [transitionContext containerView];

    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    [containerView addSubview:fromVC.view];

    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    [containerView addSubview:toVC.view];

    UIViewAnimationOptions animationOption = ([toVC.presentedViewController isEqual:fromVC])?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;

    if ([toVC class] == [ClockViewController class]) {

        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

    }

    [UIView transitionFromView:fromVC.view
                        toView:toVC.view
                      duration:0.7f
                       options:animationOption
                    completion:^(BOOL finished){
                        [transitionContext completeTransition:YES];
                    }];

}

Solution

  • Figured out a fix for my issue in case anyone has the same issue.

    Added [CATransaction commit]; before the transition and now it works.

    • (void) animateTransition:(id )transitionContext {

      UIView *containerView = [transitionContext containerView];

      UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; [containerView addSubview:fromVC.view];

      UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; [containerView addSubview:toVC.view];

      UIViewAnimationOptions animationOption = ([toVC.presentedViewController isEqual:fromVC])?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;

      [CATransaction commit];

      [UIView transitionFromView:fromVC.view toView:toVC.view duration:0.7f options:animationOption completion:^(BOOL finished){ [transitionContext completeTransition:YES]; }];

    }