一. 手势类常用的代理方法,解决手势和点击cell的冲突
手势是OC中的类,那么手势类也是有协议的,UIGestureRecognizerDelegate,手势常用的代理方法:
1.是否允许同时支持多个手势,默认只支持一个手势,要调用此方法注意设置代理 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 2.是否允许开始触发手势 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return NO; } 3.是否允许接收手机的触摸(可以控制触摸的范围) - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { //获取当前的触摸点 CGPoint currentP = [touch locationInView:self.imageView]; 在图片的左半区域可以接受触摸 if (currentP.x < self.imageView.bounds.size.width * 0.5) { return YES; }else { return NO; } }
例如:- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// 输出点击的view的类名 //NSLog(@"%@", NSStringFromClass([touch.view class]));
// 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"])
{ return NO; }
return YES;
}