iosobjective-cmodalviewcontrollerpresentmodalviewcontroller

iOS: Modal ViewController with transparent background


I'm trying to present a view controller modally, with a transparent background. My goal is to let both the presenting and presented view controllers's view to be displayed at the same time. The problem is, when the presenting animation finishes, the presenting view controller's view disappears.

- (IBAction)pushModalViewControllerButtonPressed:(id)sender
{
    ModalViewController *modalVC = [[ModalViewController alloc] init];
    [self presentViewController:modalVC animated:YES completion:nil];
}

I know I could just add the view as a subview, but I'd like to avoid this solution for some reason. How could I fix it?


Solution

  • This following code only works on the iPad.

    self.view.backgroundColor = [UIColor clearColor];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentModalViewController:modalVC animated:YES];
    

    I would go with adding a sub view.

    Here is a very good discussion. Look at the comments specifically. Not only the answer.

    Modal View

    If I were you I wouldn't do it. I would add a sub view and do it. It seems to give me a better control over things.

    EDIT:

    As mentioned by Paul Linsay, since iOS 8 all that's needed is UIModalPresentationOverFullScreen for the modalPresentationStyle of the ViewController being presented. This would also cover of navigationBar and tabBar buttons.