Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display clear colored ViewController over another ViewController in iOS 7 [duplicate]

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!

like image 587
daspianist Avatar asked Oct 21 '13 04:10

daspianist


1 Answers

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

  • You can check it here: https://github.com/codedad/SO_IOS_viewcl_on_viewcl

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!

like image 144
nzs Avatar answered Oct 19 '22 17:10

nzs