iOS7 UIModalTransitionStyleFlipHorizontal bounces after transition

后端 未结 6 1861
一整个雨季
一整个雨季 2020-12-22 18:07

I\'m updating my app for iOS 7 and I discovered a weird problem. I\'m presenting a UIViewController wrapped in a UINavigationController with UIModalTransitionStyleFlip

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 18:25

    To solve this problem for present & dismiss, I use the iOS7 custom transition.

    Add this to your UIViewController :

    - (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
        return (id)self;
    }
    
    - (id )animationControllerForDismissedController:(UIViewController *)dismissed {
        return (id)self;
    }
    
    - (NSTimeInterval)transitionDuration:(id )transitionContext {
        return 0.7f;
    }
    
    - (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;
    
    
        [UIView transitionFromView:fromVC.view
                            toView:toVC.view
                          duration:[self transitionDuration:transitionContext]
                           options:animationOption
                        completion:^(BOOL finished) {
                            [transitionContext completeTransition:YES];
                        }];
    }
    

    To use it, you just had to check if you are on iOS7 and set the transitionDelegate :

    YourVCWithTheCustomTransition* yourVC = [[YourVCWithTheCustomTransition alloc] init];
    
    CGFloat deviceVersion = [UIDevice currentDevice].systemVersion.floatValue;
    if(deviceVersion >= 7.0) [yourVC setTransitioningDelegate:yourVC];
    
    [self presentModalViewController:yourVC animated:YES];
    [yourVC release];
    

    In my case, I had a custom UINavigationController where the custom transition is defined : i don't have to do this each time.

提交回复
热议问题