如何在带有alpha的uiviewcontroller上添加全屏maskview

时间:2015-07-26 10:04:52

标签: ios objective-c

以下是我的代码段

_maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];
_maskView.backgroundColor = [UIColor redColor];
_maskView.alpha = 0.5;

UIButton *disappare = [[UIButton alloc] initWithFrame:CGRectMake(60, 200, 120, 44)];
disappare.backgroundColor = [UIColor blueColor];
disappare.alpha = 1.0;
[disappare setTitle:@"消失" forState:UIControlStateNormal];
[disappare addTarget:self action:@selector(dismissMaskView:) forControlEvents:UIControlEventTouchUpInside];
[_maskView addSubview:disappare];
[self.navigationController.view addSubview:_maskView];

我将maskView添加到navigationController.view,但是当我在maskview上设置alpha时,它会影响像enter image description here这样的maskview.subviews,

如何设置maskview.alpha无效消失按钮?

1 个答案:

答案 0 :(得分:3)

如果您设置了视图的alpha,它也将应用于其子视图。相反,您可以使用alpha作为背景颜色

[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5];

我不确定颜色代码,无论如何alpha是关键。