使用淡入淡出animation呈现模态视图

我以模态方式呈现了一个login屏幕。 纠正我,如果我不正确。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"];//LOOK AT NEXT LINE [self presentViewController:ivc animated:YES completion:nil]; 

login屏幕确实出现,但animation是向上滑动的。 我更喜欢淡入淡出我们的animation。 我怎样才能做到这一点?

只需为modalPresentationStyle设置modalPresentationStylemodalTransitionStyle属性即可。

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"login"]; [ivc setModalPresentationStyle:UIModalPresentationCustom]; [ivc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; [self presentViewController:ivc animated:YES completion:nil]; 

Swift 3,3.1 (截至2017年8月2日)

 var storyboard = UIStoryboard(name: "Main", bundle: nil) var ivc = storyboard.instantiateViewController(withIdentifier: "login") ivc.modalTransitionStyle = .crossDissolve self.present(ivc, animated: true, completion: { _ in })