19

Opened old project in Xcode 6 and found issue that background is not transparent in presented view controller. I have used solution in the topic below and it worked so far in ios7. iOS : ModalView with background transparent?

Please advice how to deal with iOS 8.

Community
  • 1
  • 1
Madman
  • 3,171
  • 2
  • 32
  • 44

5 Answers5

47

Try setting the modalPresentationStyle property of the presented view controller to the new UIModalPresentationOverCurrentContext constant e.g.

[_modalViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext]
mmccomb
  • 13,516
  • 5
  • 39
  • 46
19

mmccomb's solution eventually worked for me, but I had to tweak a couple of things. Hopefully these details help someone:

1) I had to set the property of the presented view controller from the presenting view controller, like this:

MyViewController *myVc = [segue destinationViewController];
[myVc setModalPresentationStyle:UIModalPresentationOverCurrentContext];

Setting the presentation style from within the presented VC's viewDidLoad didn't work.

2) I was using a storyboard, and I had to go into the segue properties and set the Presentation style to Default. Setting any other value gave me a black background.

itnAAnti
  • 652
  • 8
  • 17
16

Interface Builder Solution

Thanks to @mmccomb's programmatic solution.

Achieve this by:

  1. Creating a segue in your storyboard file (ctrl + click & drag)

  2. Choosing Present Modally from the dropdown options

  3. Select the Modal Segue in the IB Storyboard - (just the segue)

  4. Set Presentation in the Attributes Inspector to Over Current Context

I would recommend changing the alpha/opacity to 50% + and using a darker background color, otherwise you'll have a hard time distinguishing between the presenting view controller's content and the one you are presenting modally.

ChrisHaze
  • 2,800
  • 16
  • 20
  • Thank you very much for your solution and the steps you give. This is exactly what i'm looking for. – Tien Mar 26 '16 at 15:32
  • 1
    @ChrisHaze, I follow these steps you give I have solved my issue but when dismiss view controller previous view controller's view's methods didn't call like viewWillAppear of viewDidAppear etc. why ? – Raj Joshi Dec 22 '16 at 06:24
4

If you changed presentation style in "segue", you have to change it back to default. or it will give you a black background.

I've tried using Storyboard with Segue config, however it does not work.

here is the code works for me, in the - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender method:

// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"PresentStationChooserViewController"])
{
    ChooseStationViewController *controller = [segue destinationViewController];
    controller.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7f];
    [controller setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    controller.stationList = _remoteStations;
}
c9s
  • 1,888
  • 19
  • 15
0

iOS8+

Please take a look on below code snippet, its solved my problem,

SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;           
[self presentViewController:secondViewController animated:YES completion:nil];    
arunjos007
  • 4,105
  • 1
  • 28
  • 43