如何更改模式UIViewController的动画样式? [英] How can I change the animation style of a modal UIViewController?

查看:92
本文介绍了如何更改模式UIViewController的动画样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前显示的UIViewController这样:

I'm currently displaying a UIViewController like this:

[[self navigationController] presentModalViewController:modalViewController animated:YES];

并将其隐藏如下:

[self.navigationController dismissModalViewControllerAnimated:YES];

动画是从底部向上滑动...然后滑回来。如何更改动画样式?我可以让它淡入/淡出吗?

The animation is "slide up from the bottom"... then slide back down. How can I change the animation style? Can I made it fade in/out?

干杯!

推荐答案

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

Marcus Zarra posted a great solution to this on the SDK mailing list:

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:

There are transitions for flipping and page-curling. If you are set on fading, can try adjusting your new view's 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。

However, what you probably want is a crossfade, or at least a fade-over. When the UINavigationController switches to a new view, it removes the old one. For this effect, you're probably better off just adding a new view to your existing UIViewController and fading its alpha in over time.

注意:如果你不在你的app delegate [self window]不能工作。使用self.view.window,感谢user412500的帖子指出这一点。

Note: If you are not in your app delegate [self window] will not work. Use self.view.window , thanks to user412500's post for pointing this out.

这篇关于如何更改模式UIViewController的动画样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆