IOS - presentViewController with transparency

I would like for the view controller to be translucent in full screen mode so that I can still see the view under it. The following code introduces a new view controller, but it replaces the current one. What is the best way to keep the controller visible? The view of the new view controller will have a translucent black background.

NewViewController* newVC = [[NSClassFromString(@"NewViewController") alloc] initWithNibName:deviceNib bundle:nil];
newVC.modalPresentationStyle = UIModalPresentationFullScreen;
newVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;


[self presentViewController:newVC animated:YES completion:NULL];
+5
source share
2 answers

Imagine a translucent view, not a view controller.

mySemiTransparentView.alpha = 0.0f;
[self.view addSubview:mySemiTransparentView];

mySemiTransparentView is your full screen mode. You can animate it in place:

[UIView beginAnimations:@"fadeIn" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.4f];
mySemiTransparentView.alpha = 0.5f;
[UIView commitAnimations];
+6
source

You can imagine a translucent modal controller as follows:

NewViewController* newVC = [[NSClassFromString(@"NewViewController") alloc] initWithNibName:deviceNib bundle:nil];

self.modalPresentationStyle = UIModalPresentationCurrentContext;
newVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:newVC animated:YES completion:NULL];

, UIModalPresentationCurrentContext self.modalPresentationStyle, newVC.modalPresentationStyle

, UIModalTransitionStyleCrossDissolve, VC.view , , , newCC.view backgroundColor UIView, backgroundColor

+2

All Articles