UITableView 解决
/*1.遵守UIGestureRecognizerDelegate的协议*/
@interface ****ViewController ()<UIGestureRecognizerDelegate>
@end
/*2.Create GR对象,并且当前controller成为代理*/
-(void)viewDidLoad{
UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClicked:)];
tapGr.delegate = self;
[self.view addGestureRecognizer:tapGr];
}
/*3.实现这个代理方法*/
#pragma mark Delegate for the gestureRecognizer
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
return YES;
}
UICollectionView 处理
#pragma mark -UIGestureRecognizerDelegate
//判断是否是collectionCell 是的话不响应tap手势
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isDescendantOfView:self.collectVc]) {
if ([self.collectVc indexPathForItemAtPoint:[touch locationInView:self.collectVc]]) {
return NO;
}
}
return YES;
}
做个记录
网友评论