0

I want to hidden some contents when touching anywhere in the View. I have a view and some labels and view as subview , If I add tap gesture for the main view, all the subview get respond? or I have to add tap gesture for each subview separately?

Jan
  • 1,744
  • 3
  • 23
  • 38

1 Answers1

0

You could add touchesBegan:withEvents: inside your main UIView. Every time you touch an element inside the UIView you can get the selected element from the touch and also set it hidden:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];

    UITouch *touch = [[event allTouches] anyObject];
    touch.view.hidden = YES;
}
Alex Cio
  • 6,014
  • 5
  • 44
  • 74