IOS simulates a translucent ViewController presentViewController implementation, and ioscontroller redirects
Recently, there is a need for a project. We need to create a new translucent view. Many people have encountered this problem, set the background color in the target view and find that the modal action is black or not translucent.
So I will tell you the solution today.
- (IBAction)Avtion1:(id)sender { TestViewController * testVC = [TestViewController new]; self.definesPresentationContext = YES; //self is presenting view controller testVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4]; testVC.modalPresentationStyle = UIModalPresentationOverCurrentContext; [self presentViewController:testVC animated:YES completion:nil];}
- NOTE: If present is a NavController, the above Code cannot be used completely.
- (IBAction)pushSecond:(id)sender{
SecondViewController * testVC = [SecondViewController new];
self.definesPresentationContext = YES; //self is presenting view controller
testVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
// testVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:testVC];
nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
nav.view.backgroundColor = [UIColor clearColor];
[self presentViewController:nav animated:YES completion:nil];
}
- DefinesPresentationContext
/* Determines which parent view controller's view should be presented over for presentations of type UIModalPresentationCurrentContext. If no ancestor view controller has this flag set, then the presenter will be the root view controller.*/
Set your background color
/* Defines the transition style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter. Defaults to UIModalTransitionStyleCoverVertical.*/