模態(tài)出一個(gè)半透明的視圖,在目標(biāo)視圖中設(shè)置背景顏色然后發(fā)現(xiàn)模態(tài)動(dòng)作結(jié)束后變成了黑色或者不是半透明的顏色。
解決方案:
- (void)presentViewController {
MyAlertController * alertVC = [MyAlertController new];
alertVC.definesPresentationContext = YES; //self is presenting view controller
alertVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4];
alertVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:testVC animated:YES completion:nil];
}
注意:如果present 一個(gè)UINavigationController袱瓮,不能完全使用上面代碼。
- (void)presentNavigationController {
MyAlertController * alertVC = [MyAlertController new];
alertVC.definesPresentationContext = YES; //self is presenting view controller
alertVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
// alertVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: alertVC];
nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
nav.view.backgroundColor = [UIColor clearColor];
[self presentViewController:nav animated:YES completion:nil];
}