Sandah Aung Sandah Aung - 1 month ago 24
iOS Question

Present a modal view using fade-in animation

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?

Answer

Just set the modalPresentationStyle and modalTransitionStyle properties for the viewController.

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];