Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present a modal view using fade-in animation

Tags:

ios

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?

like image 287
Sandah Aung Avatar asked Jun 23 '15 07:06

Sandah Aung


Video Answer


1 Answers

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) 
like image 170
ZeMoon Avatar answered Sep 20 '22 21:09

ZeMoon