15

Prior to iOS 7, according to this popular Stackoverflow question, the way to show a ViewController with a clear background was to do the following in the main ViewController:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    vc.view.backgroundColor = [UIColor clearColor];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:vc animated:NO completion:nil];

However, as I have recently discovered with iOS 7 (and as commented by others to the main answer), the above solution no longer works, and instead just shows a black model controller. I know that transparency is largely used in iOS 7, so that transparent view controller is very likely possible. I haven't discovered a workaround to this issue yet, and was wondering if anyone knows how to resolve this problem. Thanks!

Community
  • 1
  • 1
daspianist
  • 5,336
  • 8
  • 50
  • 94
  • 1
    `modalPresentationStyle` documentation now states: "On iPhone and iPod touch, modal view controllers are always presented full-screen, but on iPad there are several different presentation options". So I assume Apple took this away for iPhone in iOS 7. – Ortwin Gentz Oct 21 '13 at 20:13
  • 1
    This http://stackoverflow.com/q/27598846/1603234 make me smile, now your turn :) – Hemang Dec 22 '14 at 08:15
  • Swift Verion http://stackoverflow.com/a/34578402/3380878 – Mojtaba Yeganeh Jan 03 '16 at 15:52

3 Answers3

8

I just followed the original solution and applied some default and custom settings in Interface Builder, and seems to me it is working.

Important section (quite similar to the question's code):

- (IBAction)click:(id)sender {
    NSLog(@"click");


    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"TopOverVc"];

    vc.view.backgroundColor = [UIColor clearColor];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:vc animated:NO completion:nil];
}
  • Also pls find the IB snaphot: enter image description here

  • And the simulator result (after pressing button):

enter image description here

Hope I did not misunderstand sthing in your question ;) Happy coding!

nzs
  • 3,252
  • 17
  • 22
-2

For iOS 7,subclass SecondViewController and try setting the view background color in viewDidLoad of SecondViewController

self.view.backgroundColor = [UIColor clearColor];
Meet
  • 4,904
  • 3
  • 24
  • 39
-3

Why not u r using this

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:vc animated:NO completion:nil];

 vc.view.backgroundColor = [UIColor clearColor];

Try to change BG Color of View after view is loaded. in ur sol u r first changing View and the presenting. the View Life cycle not going on this manner

Satish Azad
  • 2,302
  • 1
  • 16
  • 35