开发中会遇到这种情况:一个大的透明蒙版,上面加一个不透明的子视图,比如自定义的类似AlertView的东西。这个时候会发现,如果设置蒙版为透明的,子视图也看不到了。解决方法如下:
//创建蒙版 UIView* coverView = [[UIViewalloc]initWithFrame:[UIScreenmainScreen].bounds]; //这么写可以使蒙版透明,而子视图不透明 coverView.backgroundColor= [[UIColorblackColor]colorWithAlphaComponent:0.6]; [self.viewaddSubview:coverView];