Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use presentModalViewController to create a transparent view

I am displaying a modal view with

[self presentModalViewController:controller animated:YES]; 

When the view moves up the screen it is transparent as per the setting in the xib file it is created from, but once it fills the screen it goes opaque.

Is there anyway of keeping the view transparent?

I suspect that the view it is being placed over is not being rendered rather then that the modal view is becoming opaque.

like image 529
Darryl Braaten Avatar asked Feb 25 '09 20:02

Darryl Braaten


1 Answers

After iOS 3.2 there is a method to do this without any “tricks” – see the documentation for the modalPresentationStyle property. You have a rootViewController which will present the viewController. So here's the code to success:

viewController.view.backgroundColor = [UIColor clearColor]; rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext; [rootViewController presentModalViewController:viewController animated:YES]; 

With this method the viewController's background will be transparent and the underlying rootViewController will be visible. Please note that this only seems to work on the iPad, see comments below.

like image 132
Infinite Possibilities Avatar answered Oct 05 '22 04:10

Infinite Possibilities