Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I overlay a modalViewController on top of another view without the original disappearing?

I want to show a customised alert panel over my app, but have the previous UIViewController visible in the background. I was hoping to show this as a modal view controller. How do I do this without the previous UIViewController turning black and disappearing?

like image 407
Andrew Avatar asked Oct 28 '12 16:10

Andrew


People also ask

How do I make ViewController transparent?

navigationController. modalPresentationStyle = UIModalPresentationCurrentContext; then it works and my view is transparent.

How do I know if a ViewController is visible?

The view's window property is non-nil if a view is currently visible, so check the main view in the view controller: Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded.


1 Answers

Instead of showing the new vc as a modal vc, you need to add it as child view controller:

AlertPanelVC *alertVC = ...
[self addChildViewController: alertVC];
alertVC.view.frame = ...; //or something equivalent if you're using auto layout 
[self.view addSubview: alertVC.view];
[alertVC didMoveToParentViewController: self];

To dismiss it:

[alertVC willMoveToParentViewController:nil];
[alertVC.view removeFromSuperview];
[alertVC removeFromParentViewController];
like image 200
Tobi Avatar answered Nov 09 '22 22:11

Tobi