1

I have this grayView that disables the controller and makes it look inactive courtesy to a previous question I asked, but I need to detect if grayView is touched and if it touched get rid of the grayView. If anyone can help me figure out a solution to this I would deeply appreciate it. I tried using UITouchedBegan and many other stackoverflow solutions but each one didn't work. Any help will be appreciated.

grayView is an UIView.

-(void)ViewDidLoad
{
    grayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    grayView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    [self.navigationController.view addSubview:grayView];
}
Akshit Zaveri
  • 4,166
  • 6
  • 30
  • 59
This Is
  • 137
  • 7

1 Answers1

2

you can add a UITapGestureRecognizer to the grayView, and when touched, remove the grayView from superview.

Here's how I would do it.

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

Make sure you add this code before you add your grayView to your superView

Then,

-(void) removeGrayView: (UITapGestureRecognizer*) gesture {
     [_yourGrayView removeFromSuperView];
}
uplearned.com
  • 3,393
  • 5
  • 44
  • 59
Laurent Rivard
  • 509
  • 4
  • 13