2016-03-04 2 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; 
    } 

В 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]]; 
    }]; 
} 
Смежные вопросы