0
votes

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];
2
can you put some code of model present? - Yagnesh Dobariya
@yagneshdobariya I've edited the question, plz have a look - Sagar D
pls have a look on answer. - Yagnesh Dobariya

2 Answers

0
votes

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.

0
votes
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 dismisViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.view.alpha = 1.0f;
    [self.navigationController.navigationBar setHidden:NO];
}