我按模式提供了一个登录屏幕。如果我不对,请纠正我。
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];//LOOK AT NEXT LINE
[self presentViewController:ivc animated:YES completion:nil];
登录屏幕确实出现,但动画是向上滑动的。我更喜欢淡入淡出动画。我怎么能这样做?
答案 0 :(得分:111)
只需为viewController设置modalTransitionStyle
属性即可。 (Documentation)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];
[ivc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:ivc animated:YES completion:nil];
在斯威夫特:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "login")
viewController.modalTransitionStyle = .crossDissolve
present(viewController, animated: true, completion: nil)
答案 1 :(得分:43)
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)
答案 2 :(得分:5)
你必须设定预设和过渡风格:
self.activityAlertVC.modalPresentationStyle = .custom
self.activityAlertVC.modalTransitionStyle = .crossDissolve