我目前正在显示如下的UIViewController:
[[self navigationController] presentModalViewController:modalViewController animated:YES];
并将其隐藏起来:
[self.navigationController dismissModalViewControllerAnimated:YES];
动画“从底部向上滑动”......然后向下滑动。如何更改动画样式?我可以让它淡入/淡出吗?
干杯!
答案 0 :(得分:194)
对于iPhone 3.0+,基本的交叉淡入淡出最容易做到:
modalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[[self navigationController] presentModalViewController:modalViewController
animated:YES];
答案 1 :(得分:60)
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的帖子指出这一点。
答案 2 :(得分:8)
要更新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;}];
答案 3 :(得分:2)
为了使代码正常工作,应为[self.view.window]
(至少那是它在ios 3.2中的方式)