5

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

现在,我想在两者之间有一个自定义动画,如下所示: 自定义动画

总之,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 之类的,所以我看不到淡入淡出的来源。

任何我没有得到预期结果的建议将不胜感激。抱歉,如果这很明显,但我现在尝试了几个小时并且非常沮丧。

4

2 回答 2

3

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

于 2011-10-05T15:45:05.290 回答
1

我想这样做的唯一方法是忘记 UINavigationController 并提出我自己的机制来处理所有事情:

这个博客解释了如何...

所以如果你想自定义 VC 之间的动画,不要使用 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];


}
于 2011-10-05T20:01:32.930 回答