62

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?

Sandah Aung
  • 6,156
  • 15
  • 56
  • 98
  • possible duplicate of [How can I change the animation style of a modal UIViewController?](http://stackoverflow.com/questions/237310/how-can-i-change-the-animation-style-of-a-modal-uiviewcontroller) – App Dev Guy Jun 23 '15 at 07:28

3 Answers3

147

Just set the modalTransitionStyle property for the viewController. (Documentation)

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)
ZeMoon
  • 20,054
  • 5
  • 57
  • 98
  • 1
    Yours is a better way than [this one](http://stackoverflow.com/questions/237310/how-can-i-change-the-animation-style-of-a-modal-uiviewcontroller). – Sandah Aung Jun 23 '15 at 07:29
  • 9
    Well, that's an answer from 2008. I'm sure these properties were not available at that time. If you look at the most voted up answer there, you will see they have suggested the same thing. – ZeMoon Jun 23 '15 at 07:31
  • I must admit I did miss out on those ones. – Sandah Aung Jun 23 '15 at 07:33
  • if you use `.partialCurl`, make sure the parent view controller's `.modalPresentationStyle` is `.fullScreen`. Source: https://developer.apple.com/documentation/uikit/uimodaltransitionstyle/partialcurl – spnkr Aug 13 '19 at 22:44
50

Swift 3, 3.1, 4, 4.2 (as of January, 2021)

var storyboard = UIStoryboard(name: "Main", bundle: nil)
var loginViewController = storyboard.instantiateViewController(withIdentifier: "login")
loginViewController.modalTransitionStyle = .crossDissolve
self.present(loginViewController, animated: true, completion: nil)
BennyTheNerd
  • 3,930
  • 1
  • 21
  • 16
7

You have to set prestentation and transition style:

    self.activityAlertVC.modalPresentationStyle = .custom
    self.activityAlertVC.modalTransitionStyle = .crossDissolve
  • 8
    Do not set the `modalPresentationStyle` to `.custom` unless you also set the `transitioningDelegate` to support the custom transition. The presentation style has nothing to do with the transition style. – rmaddy Aug 09 '19 at 20:30