我想在触摸视图中的任意位置时隐藏一些内容。我有一个视图和一些标签,视图作为子视图,如果我为主视图添加点击手势,所有子视图都会得到响应?或者我必须为每个子视图单独添加点击手势?
您可以在
主UIView
中添加touchesBegan:withEvents:
。每次触摸UIView
内的元素时,您都可以从触摸中获取所选元素并将其隐藏:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
UITouch *touch = [[event allTouches] anyObject];
touch.view.hidden = YES;
}