IOS simulates a translucent ViewController presentViewController implementation, and ioscontroller redirects

Source: Internet
Author: User

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.*/
  • BackgroundColor
Set your background color
  • ModalPresentationStyle
/*  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.*/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.