2016-03-04 56 views
1

我想從一個視圖控制器「A」,第二個ViewController「B」(帶有導航欄),它應該顯示第三個模式ViewController「C」,它顯示倒數和解散本身,最後顯示「B」。目前2個視圖控制器,但只有一個轉換

我希望模態地呈現「C」,沒有看到「B」,當它被解散時,「B」應該已經在那裏。

我一直在尋找這樣的帖子:

但因爲我需要 「B」 被推(非模態),我不能使用UIModalPresentationCurrentContext

我也試過這樣做:How to push two view controllers but animate transition only for the second one?

這幾乎是我想要的,但我希望「C」以模式風格呈現,例如封面垂直。

回答

2

我終於結束了做這兩個混合:

在VCB:

-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC 
    { 
     if (operation == UINavigationControllerOperationPush || operation == UINavigationControllerOperationPop) { 
      MyAnimator *animator = [[MyAnimator alloc] init]; 
      animator.presenting = (operation == UINavigationControllerOperationPush); 
      return animator; 
     } 
     return nil; 
    } 

In MyAnimator.m:

-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext 
{ 
    return 0.4; 
} 

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

    [[transitionContext containerView] addSubview:toViewController.view]; 

    CGRect currentFrame = toViewController.view.frame; 
    CGRect toFrameInitial = self.presenting ? CGRectOffset(currentFrame, 0, CGRectGetHeight(currentFrame)) : CGRectOffset(currentFrame, 0, -CGRectGetHeight(currentFrame)); 
    CGRect fromFrameFinal = self.presenting ? CGRectOffset(currentFrame, 0, -CGRectGetHeight(currentFrame)) : CGRectOffset(currentFrame, 0, CGRectGetHeight(currentFrame)); 

    toViewController.view.frame = toFrameInitial; 
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
     toViewController.view.frame = currentFrame; 
     fromViewController.view.frame = fromFrameFinal; 
    } completion:^(BOOL finished) { 
     [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; 
    }]; 
} 
相關問題