问题描述:
给父视图上添加一个子视图,给父视图添加一个手势识别器UITapGestureRecognizer,点击子视图时,也会触发UITapGestureRecognizer所关联的事件,导致子视图不能响应本身事件。
使用示例如图:
解决方法:
使用UIGestureRecognizerDelegate的代理方法-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch,将子视图的tap手势屏蔽
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isDescendantOfView:self.collectionView]) {
return NO;
}
return YES;
}