前言:开发中遇到弹出一个半透明的controller的情况,用presentViewController方式弹出时背景色是黑的
解决方法:
1.在弹出时设置弹出模式
FaHuoVC *vc = [[FaHuoVC alloc] initNoChecking];
//全屏幕覆盖
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext|UIModalPresentationFullScreen;
//设置弹出动画:淡入淡出
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:nil];
2.在半透明控制器中重写init方法
- (instancetype)init {
self = [super init];
if (self) {
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[self.bgView cornerRadius:6];
}
return self;
}