代码改变世界

present半透明UIViewController

2015-12-21 14:19  蓝梦儿  阅读(422)  评论(0编辑  收藏  举报

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:^{
                
            }];