1

我有这个grayView禁用控制器并使其看起来不活动的礼貌我之前问过的问题,但我需要检测是否grayView被触摸,如果它被触摸,请摆脱grayView. 如果有人可以帮助我找到解决方案,我将不胜感激。我尝试使用UITouchedBegan和许多其他 stackoverflow 解决方案,但每个都不起作用。任何帮助将不胜感激。

grayView是一个UIView

-(void)ViewDidLoad
{
    grayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    grayView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    [self.navigationController.view addSubview:grayView];
}
4

1 回答 1

2

您可以在 中添加UITapGestureRecognizergrayView当触摸时,grayView从中删除superview

这就是我将如何做到的。

//your gray view
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self   action:@selector(removeGrayView:)];
tap.numberOfTapsRequired = 1;
[_yourGrayView addGestureRecognizer:tap];

确保在添加您的代码之前添加此grayView代码superView

然后,

-(void) removeGrayView: (UITapGestureRecognizer*) gesture {
     [_yourGrayView removeFromSuperView];
}
于 2013-10-31T17:49:04.107 回答