Present a modal view using fade-in animation

Ios

Ios Problem Overview


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?

Ios Solutions


Solution 1 - Ios

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)

Solution 2 - Ios

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)

Solution 3 - Ios

You have to set prestentation and transition style:

    self.activityAlertVC.modalPresentationStyle = .custom
    self.activityAlertVC.modalTransitionStyle = .crossDissolve
    
    
    

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSandah AungView Question on Stackoverflow
Solution 1 - IosZeMoonView Answer on Stackoverflow
Solution 2 - IosBennyTheNerdView Answer on Stackoverflow
Solution 3 - IosJavier Calatrava LlaveríaView Answer on Stackoverflow