Reputation: 2618
I'm presenting a SecondViewController
modally on FirstViewController
and the SecondViewController
has a semi transparent background (White color with 70 percent opacity).
The problem I'm facing is when I present SecondViewController
, the view of FirstViewController
remains visible until the SecondViewController
has finished presenting.
This makes the UI look laggy. The behaviour I'm expecting is as soon as the SecondViewController
is presented, the view for FirstViewController
should be invisible, or gradually faded out before the view of SecondViewController
appears.
Any help will be greatly appreciated!
The code I use for presenting is :
SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:@“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
[self presentViewController:cntrlr animated:YES completion:nil];
Upvotes: 0
Views: 522
Reputation: 2251
SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:@“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
self.view.alpha = 0.0f;
[self.navigationController.navigationBar setHidden:YES];
[self presentViewController:cntrlr animated:YES completion:nil];
// Need to set FirstViewController alpha 1.0f after dismisViewControlle
r
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.view.alpha = 1.0f;
[self.navigationController.navigationBar setHidden:NO];
}
Upvotes: 0
Reputation: 1204
After iOS 3.2 there is a method to do this without any “tricks” – see the documentation for the modalPresentationStyle property. You have a rootViewController which will present the viewController. So here's the code to success:
viewController.view.backgroundColor = [UIColor clearColor];
rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[rootViewController presentModalViewController:viewController animated:YES];
With this method the viewController's background will be transparent and the underlying rootViewController will be visible.
Upvotes: 0