tabbarcontroller上的navigationcontroller的ios7自定义转换

时间:2014-03-05 03:35:30

标签: ios7 custom-transition

我的ViewController层次结构如下:

UITabbarcontroller
->UINavigationController1
   ->FirstViewController
->UINavigationController2
   ->UIViewController

所以我想在我的FirstViewController之上推送一个SecondViewController。我需要的自定义转换是让SecondViewController淡入,我的FirstViewController淡出。

这是我的代码:

FirstViewController:

- (void)didTapButton:(id)sender
{
    SecondViewController* vc = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

UINavigationController1Delegate:

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
    MyAnimatedTransitioning *transitioning = [[MyAnimatedTransitioning alloc] init];
    return transitioning;
}

MyAnimatedTransitioning:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    [transitionContext.containerView addSubview:toViewController.view];
    toViewController.view.alpha = 0;
    fromViewController.view.alpha = 1.0;

    [UIView animateKeyframesWithDuration:0.25 delay:0 options:0 animations:^{
            fromViewController.view.alpha = 0;
            toViewController.view.alpha = 1.0;

    } completion:^(BOOL finished) {

        fromViewController.view.alpha = 1.0;
        [transitionContext completeTransition:finished];
    }];
}

我使用推送样式而不是现在的样式,以便导航栏可以很好地交叉淡入淡出。 然而,我面临的问题是,在转换过程中,我仍然看到底部的tabbar(来自tabbarcontroller)被推到左侧。我需要的是tabbar也能很好地淡出。任何人对如何做到这一点都有好的想法?

1 个答案:

答案 0 :(得分:0)

我最终使用的是现代风格而不是推送风格。对我来说效果很好