Iphone 如何更改模态UIViewController的动画样式?

Iphone 如何更改模态UIViewController的动画样式?,iphone,cocoa-touch,Iphone,Cocoa Touch,我当前显示的UIViewController如下所示: [[self navigationController] presentModalViewController:modalViewController animated:YES]; [self.navigationController dismissModalViewControllerAnimated:YES]; modalViewController.modalTransitionStyle = UIModalTransitionS

我当前显示的UIViewController如下所示:

[[self navigationController] presentModalViewController:modalViewController animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[[self navigationController] presentModalViewController:modalViewController
                                               animated:YES];
然后像这样隐藏它:

[[self navigationController] presentModalViewController:modalViewController animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[[self navigationController] presentModalViewController:modalViewController
                                               animated:YES];
动画是“从底部向上滑动”。。。然后滑下。如何更改动画样式?我能让它淡入/淡出吗


干杯

Marcus Zarra在SDK邮件列表中发布了一个很好的解决方案:

UIViewController *controller = [[[MyViewController alloc] init] autorelease];
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[navController presentModalViewController: controller animated: NO];
[UIView commitAnimations];
翻页和卷页有过渡。如果设置为淡入淡出,可以尝试调整新视图的alpha:

UIViewController *controller = [[[MyViewController alloc] init] autorelease];
controller.view.alpha = 0.0;
[navController presentModalViewController: controller animated: NO];
[UIView beginAnimations: nil context: nil];
controller.view.alpha = 1.0;
[UIView commitAnimations];
然而,您可能需要的是交叉淡入淡出,或者至少淡入淡出。当UINavigationController切换到新视图时,它会删除旧视图。为了达到这种效果,您最好只向现有UIViewController添加一个新视图,并随时间逐渐淡入其alpha


注意:如果您不在应用程序中,代理[自窗口]将不工作。使用self.view.window,感谢user412500的帖子指出这一点。

对于iPhone 3.0+,基本的交叉淡入淡出是最容易做到的:

[[self navigationController] presentModalViewController:modalViewController animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];
modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[[self navigationController] presentModalViewController:modalViewController
                                               animated:YES];

它应该是
[self.view.window]
,这样代码才能工作


(至少在ios 3.2中是这样的)

要在ios 4中更新alpha衰落:

modalController.view.alpha = 0.0;
[self.view.window.rootViewController presentModalViewController:modalController animated:NO];
[UIView animateWithDuration:0.5
                 animations:^{modalController.view.alpha = 1.0;}];

工作完美!!!我花了几秒钟的时间才意识到转换必须应用于正在显示的而不是自身的viewController。您可以在Interface Builder中执行此操作,例如,添加一个模式segue并将转换设置为“交叉溶解”。这太旧了!请参见下面Simo Salminen的答案!你应该切换这个