我有一个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];问题如下:
任何建议,为什么我没有得到预期的结果,将非常感谢。抱歉,如果这是显而易见的,但我尝试了几个小时,并感到非常沮丧。
发布于 2011-10-05 20:01:32
我认为唯一能做到这一点的方法是忘记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-05 15:45:05
我认为您应该使用[[self navigationController] pushViewController:vctwo animated:NO];而不是animated:YES。
https://stackoverflow.com/questions/7663707
复制相似问题