Transparent Background Modal View

Guides By 2 years ago

I wanted to create a modal View Controller that would have a transparent background but when I tried setting the alpha of the background to 0.5 it just made the view behind it completely black. This is because the background views are being removed after the transition.

invisibleBGModal

 

Screen Shot 2015-01-14 at 9.41.19 pm

To allow the modal view to have a see through background you have to add the following code.

In the presenting View Controller add the following code if you want to support iOS7.


//	For iOS modal presentation style must be set on presenting view controller.
	if ([UIDevice currentDevice].systemVersion.integerValue >= 7)
		[self setModalPresentationStyle:UIModalPresentationCurrentContext];
		
	[self presentViewController:seeThroughViewController animated:YES completion:nil]; 

In the modal View Controller code add the following code


//	Allows the presenting View Controller to be seen through the modal view controller
[self setModalPresentationStyle:UIModalPresentationCustom];

invisibleBGModal2

Screen Shot 2015-01-14 at 9.39.52 pm

 

 

The Background View is no longer removed and can be seen behind the transparent modal view.