开发中遇到了这个问题,刚开始加了两个手势,写了下面的手势代理方法,仍不起作用,还以为这个方法不能用呢,查了很多资料,都是这么说解决冲突的,最后发现了第二个手势也要遵循其协议,然后就解决了,耽误了不少时间
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
tapGestureRecognizer.delegate = self;//遵循手势协议//将触摸事件添加到当前view
[self.view addGestureRecognizer:tapGestureRecognizer];
实现下面的手势代理方法就能解决这个问题了
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
return YES;
}