Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Semi-transparent modal view controller

Tags:

I want to present a view controller with a slightly transparent background modally over the current view, such that the first view is slightly visible under the modal view.

I set the alpha value of the modal view controller and set the modalPresentationStyle to UIModalPresentationCurrentContext, as suggested in another post.

The result is that the view background is transparent when animating up, but when view controller is in place it changes to opaque black. It goes back to being transparent while animating the dismissal.

How can I get it to be transparent when active ?

I have tested in iOS 6 and 7. The code I am using follows:

MyModalViewController *viewController = [[MyModalViewController alloc] init]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController]; [navController setNavigationBarHidden:YES]; self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext; [self.navigationController presentViewController:navController animated:YES completion:NULL]; 
like image 622
Drew C Avatar asked Sep 19 '13 18:09

Drew C


1 Answers

iOS 8 added a new modal presentation style specifically for this purpose:

presentedViewController.modalPresentationStyle = UIModalPresentationOverFullScreen 

From the spec:

UIModalPresentationOverFullScreen

A view presentation style in which the presented view covers the screen. The views beneath the presented content are not removed from the view hierarchy when the presentation finishes. So if the presented view controller does not fill the screen with opaque content, the underlying content shows through.

like image 177
jburns20 Avatar answered Sep 29 '22 10:09

jburns20