ios 使用淡入动画呈现模态视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30996195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Present a modal view using fade-in animation
提问by Sandah Aung
I presented a login screen as follows modally. Correct me if I am not right.
我以模态方式呈现了一个登录屏幕,如下所示。如果我不对,请纠正我。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];//LOOK AT NEXT LINE
[self presentViewController:ivc animated:YES completion:nil];
The login screen does appear but the animation is a slide up one. I prefer a fade in and fade our animation. How can I do this?
登录屏幕确实出现,但动画是向上滑动的。我更喜欢淡入淡出我们的动画。我怎样才能做到这一点?
回答by ZeMoon
Just set the modalTransitionStyle
property for the viewController. (Documentation)
只需设置modalTransitionStyle
viewController的属性即可。(文档)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];
[ivc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:ivc animated:YES completion:nil];
In Swift:
在斯威夫特:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "login")
viewController.modalTransitionStyle = .crossDissolve
present(viewController, animated: true, completion: nil)
回答by BennyTheNerd
Swift 3, 3.1, 4, 4.2(as of November 8, 2018)
Swift 3、3.1、4、4.2 (截至 2018 年 11 月 8 日)
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var loginViewController = storyboard.instantiateViewController(withIdentifier: "login")
loginViewController.modalTransitionStyle = .crossDissolve
self.present(loginViewController, animated: true, completion: nil)
回答by Javier Calatrava Llavería
You have to set prestentation and transition style:
您必须设置演示和过渡样式:
self.activityAlertVC.modalPresentationStyle = .custom
self.activityAlertVC.modalTransitionStyle = .crossDissolve