Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent ViewController to See Parent Below?

Tags:

I would like to modally add a view controller with a transparent background, so the parent view controller beneath can be seen. (This is in an app for iPhone, not for iPad.)

I have tried this:

TextFieldViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"TextFieldVC"]; vc.modalPresentationStyle = UIModalPresentationCurrentContext; vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self.navigationController presentViewController:vc animated:YES completion:^{}]; 

Without luck and given the view controller a clear color background. My view controller is in a storyboard if that changes anything.

like image 327
Josh Kahane Avatar asked Dec 02 '12 10:12

Josh Kahane


People also ask

How do I present a transparent ViewController?

When you modally present a view controller the , it goes on the stack which in turn hides the view controller below it. So all you can do is to present a transparent view with animation similar to modally presenting a view controller.

How do you make a ViewController transparent in Swift?

#1 Open the ViewController This would open the ViewController without any fancy animations, but we want moooore. So, to make the UI popover transparent, we need to set the modalPresentationStyle to . overFullScreen . And to avoid the blurry background swiping in from the bottom, we set the modalTransitionStyle to .


2 Answers

@Josh Kahane set the view controller that will present the transparent view controller with this code at the -ViewDidLoad and be sure to set the alpha channel of the UIViewController View to be lower then 1.

Code:

self.modalPresentationStyle = UIModalPresentationCurrentContext; 
like image 98
or azran Avatar answered Sep 28 '22 08:09

or azran


I have been searching for the solution. Now thanks to iOS 8. They has introduced couple of new modalPresentationStyle. one among them is UIModalPresentationOverCurrentContext. Used the same to solve the this issue.

viewcontroller.modalPresentationStyle = UIModalPresentationOverCurrentContext; 

Hope this helps.

like image 43
Abhijit Avatar answered Sep 28 '22 07:09

Abhijit