在做項目的時候杉编,需要將一個新的controller蓋到上層controller上,而且新的controller背景是半透明的,可以顯示出上層controller的內(nèi)容。為實現(xiàn)這一需求瓶颠,需要在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];