在做项目的时候,需要将一个新的controller盖到上层controller上,而且新的controller背景是半透明的,可以显示出上层controller的内容。为实现这一需求,需要在present新的controller的时候,这样写:
NewViewController *vc = [[NewViewController alloc]init];
self.definesPresentationContext = YES; //self is presenting view controller
vc.view.backgroundColor = [UIColor clearColor];
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:vc animated:NO completion:nil];