标签:bool 响应 self targe .com nbsp delegate des select
最近为了解决 点击子视图却依然会响应父试图的点击事件发现UITapGestureRecognizer上的一个代理方法:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
如果返回no则不响应,因此我们可以根据isDescendantOfView:方法来判定一个视图是否在其父视图的视图层中。把我们不想让其响应的子视图拿出来判断一下,如果包含这个子视图就返回no,否则就是yes。
具体写法:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self
action:@selector(removeSubviews)];
tap.delegate = self;
self.userInteractionEnabled = YES;
[self.alpha_back_view addGestureRecognizer:tap];
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isDescendantOfView:self.tableView_back_view]) {
return NO;
}
return YES;
}
标签:bool 响应 self targe .com nbsp delegate des select
原文地址:http://www.cnblogs.com/wubangbang/p/6362876.html