Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - presentViewController with transparency

I would like to present a view controller full screen semi-transparently so that I still see the view underneath it. The following code presents the new view controller, but it replaces the current one. What is the best way to keep the original view controller visible? The view of the new view controller will have a semi-transparent black background.

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


[self presentViewController:newVC animated:YES completion:NULL];
like image 875
soleil Avatar asked Aug 09 '12 19:08

soleil


1 Answers

Present a semi-transparent View, not a view controller.

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

mySemiTransparentView is your full-screen view. You can animate it into place:

[UIView beginAnimations:@"fadeIn" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.4f];
mySemiTransparentView.alpha = 0.5f;
[UIView commitAnimations];
like image 70
CSmith Avatar answered Sep 27 '22 21:09

CSmith