present半透明UIViewController

present一个半透明的UIViewController,跟add个view差不多的意思,一般会遇到的问题是跳转到下一个页面加载完背景色又变回去了,没有半透明的效果,加上一句代码就好了。

1,present 一个UIViewController

SecondViewController *secondVC = [[SecondViewController alloc]init];
            secondVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            [self.navigationController presentViewController:secondVC animated:YES completion:^{
                
            }];

2,present 一个UINavigationController,注意修改的是UINavigationController的modalPresentationStyle。

SecondViewController *secondVC = [[SecondViewController alloc]init];
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:secondVC];
            nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            [self.navigationController presentViewController:nav animated:YES completion:^{
                
            }];
原文地址:https://www.cnblogs.com/lilufeng/p/5050362.html