ios 手势冲突

今天有人问我collectionView 的左滑和 cell中的左滑手势冲突怎么处理

目前有两个处理方式 适用于 UIscrollView UItableView UICollection 等

1.让手势共同存在

```

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

{

NSLog(@"当前手势:%@; 另一个手势:%@", gestureRecognizer, otherGestureRecognizer);

return YES;

}

```

2.使用hitTest响应者链

```

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

{

NSString *className=NSStringFromClass([[super hitTest:point withEvent:event] class]);

if ([className isEqualToString:@"你的含有手势的类名"]) {

self.collectionView.scrollEnabled=NO;

return [super hitTest:point withEvent:event];

}

else

{

self.collectionView.scrollEnabled=YES;

return [super hitTest:point withEvent:event];;

}

}

```

你可能感兴趣的:(ios 手势冲突)