Why is the UIView transitionFromView in animateTransition from iOS7 ok but iOS8 doesn't have animation

I want to make an animation during presentViewController:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *toView = toVC.view;
    UIView *fromView = fromVC.view;
    UIView* containerView = [transitionContext containerView];
    [containerView addSubview:toView];
    NSTimeInterval duration = 0.35;
    [UIView transitionFromView:fromView toView:toView duration:duration options:(self.reverse?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight) | 
    UIViewAnimationOptionAllowUserInteraction completion:^(BOOL finished) {
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    }];
}

this works fine on iOS7, but there is no animation on iOS8.

+4
source share
2 answers

+transitionFromView:toView:duration:options:completion:performs work on processing the hierarchy of views. You do not need [containerView addSubview:toView].

Somewhere inside, +transitionFromView:toView:duration:options:completion:inside should be the following code:

UIView *superview = fromView.superview;
[fromView removeFromSuperview];
[superview addSubview:toView];

You tried to remove the code containerView:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *toView = toVC.view;
    UIView *fromView = fromVC.view;
    NSTimeInterval duration = 0.35;
    [UIView transitionFromView:fromView toView:toView duration:duration options:(self.reverse?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight) | 
    UIViewAnimationOptionAllowUserInteraction completion:^(BOOL finished) {
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    }];
}
+2
source

Use Autolayout , . . . , iOS8, Auto Layout .

+1