5

我有一个UINavigationController。我将VC1作为rootViewController并以编程方式从VC1加载VC2,然后将自定义动画从VC1转到VC2。标准。一切都很好,很好。现在自定义UINavigationController动画:CATransition

,我想有两个之间的自定义动画像这样: Custom animation

总之,VC1滑出的观点,而VC2是它下面。就像一叠纸,您可以将第一张纸(VC1)滑走,从而显示下方的纸张(VC2)。

所以我试着从VC1调用以下代码来获得VC2。但也有与它的问题:

MyVC2 *vctwo = [[[MyVC2 alloc] init] autorelease]; 

CATransition *transition = [CATransition animation]; 
transition.duration = 1; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
transition.type = kCATransitionReveal; 
transition.subtype = kCATransitionFromRight; 
transition.delegate = self; 
[self.navigationController.view.layer addAnimation:transition forKey:nil]; 

[[self navigationController] pushViewController:vctwo animated:YES]; 

的问题如下:

  1. VC2是不固定的背景。它也可以滑入(即使我指定了kCATransitionReveal)。我想在后台完全修复VC2。
  2. VC1淡出。我不知道为什么。我没有使用kCATransitionFade之类的东西,所以我看不到淡入淡出的地方。

任何建议为什么我没有得到预期的结果将非常感激。对不起,如果这是显而易见的,但我现在试了几个小时,真的很沮丧。

回答

1

我想做到这一点的唯一方法就是忘记UINavigationController的,并拿出我自己的机制来处理一切:

This blog explains how...

所以,如果你想风险投资之间的自定义动画,不使用的UINavigationController 。这里是如上所述的两个VC之间交换的示例代码:

-(void)slideDoorOpenTo:(UIViewController *)aController duration:(float)aDuration { 

    [aController viewWillAppear:YES]; 
    [activeController viewWillDisappear:YES]; 

    //aController.view.alpha = 0.0f; 
    [self.view insertSubview:aController.view belowSubview:activeController.view]; // so that it is below activeController 

    [aController viewDidAppear:YES]; 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:aDuration]; 

    aController.view.transform = CGAffineTransformMakeTranslation(0,0); 
    activeController.view.transform = CGAffineTransformMakeTranslation(-320,0); 

    [UIView commitAnimations]; 

    [self performSelector:@selector(animationDone:) withObject:aController afterDelay:aDuration]; 


} 
3

我认为你应该使用[[self navigationController] pushViewController:vctwo animated:NO];而不是animated:YES

+0

感谢Ole,我改变了它,VC2不再移动。应该想到它。虽然有关于淡入淡出的想法?我仍然看不到淡出动画的来源。 –

+0

我认为淡入淡出实际上是UINavigationController动画的组成部分,我似乎无法摆脱它。你知道任何方式来禁用UINavigationController实现的自定义淡入淡出动画吗? –