如图,是蓝色父视图blueView添加tap事件,内部红色子视图redView的tap事件将会无法触发
解决办法
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(itemCLick)];
tap.delegate = self;
[self.blueView addGestureRecognizer:tap];
[self.blueView addSubView:self.redView];
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
//解决点击子视图父视图事件相应的问题
CGPoint point = [gestureRecognizer locationInView:self.blueView];//获取手势点击坐标
if(CGRectContainsPoint(self.redView.frame, point)) {
//判断点是否在子视图范围内
return NO;//父视图点击事件不响应
}
return YES;//父视图点击事件响应
}
标签:tap,self,iOS,视图,blueView,点击,事件
From: https://www.cnblogs.com/qqcc1388/p/17791099.html