Question

I am using the following code in my presenting VC to fade in the child modal VC, and this works fine:

self.infoViewController.view.alpha = 0.0;
[self.navigationController presentModalViewController:self.infoViewController animated:NO];
[UIView animateWithDuration:0.5
             animations:^{self.infoViewController.view.alpha = 1.0;}];

However I can't get it to fade out, I have tried a few things, this is the latest I tried that doesn't work:

- (IBAction)dismissAction:(id)sender
{
if ([[self parentViewController] respondsToSelector:@selector(dismissModalViewControllerAnimated:)])
{
    [[self parentViewController] dismissModalViewControllerAnimated:YES];
    self.parentViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    self.parentViewController.view.alpha = 0.0;
    [UIView animateWithDuration:0.5
                     animations:^{self.parentViewController.view.alpha  = 1.0;}];
} else 
{
    [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
    self.presentedViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    self.presentedViewController.view.alpha = 0.0;
    [UIView animateWithDuration:0.5
                     animations:^{
                         self.presentedViewController.view.alpha  = 1.0;}];
}

}

The modal view controller is faded out but immediately, not over a time period like it is when its displayed.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top