iphoneobjective-cipaduimodaltransitionstyleuimodalpresentationstyle

UIModalPresentationCurrentContext with Transition?


I am trying to modal present a view controller like below:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"addPopover"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:YES];

Now using UIModalPresentationCurrentContext means I can present this view with a transparent background and see my other view behind the new one. However, it stops me from being able to present it with a transition.

Any ideas why? Or how I can get around this? Thanks.


Solution

  • Full screen modals aren't supposed to allow you to see the under layer. Annoying I know.

    From your code I'm assuming that "addPopover" is actually a full screen view, where you have your content as a subsection while the rest is transparent.

    Try this:

    vc.modalPresentationStyle = UIModalPresentationCurrentContext;
    vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:vc animated:YES completion:NULL];
    

    Note: I'd recommend adding a low alpha background color to let the user know that they can't interact with the rest of the view when you pop this over top...