TabViewCell添加长按手势
UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
[_commentTabView addGestureRecognizer:longPressGR];
- (void)longPressAction:(UILongPressGestureRecognizer *)longPressGR
{
if (longPressGR.state == UIGestureRecognizerStateBegan) {
CGPoint point = [longPressGR locationInView:_commentTabView];
NSIndexPath *indexPath = [_commentTabView indexPathForRowAtPoint:point];
if(indexPath == nil){
return;
}
}
}
获取屏幕中点击位置
UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
CGRect rect=[btn convertRect: btn.bounds toView:window];
获取cell位置
CGRect rectInTableView = [_chatTabview rectForRowAtIndexPath:currentIndexPath];
CGRect rectInSuperview = [_chatTabview convertRect:rectInTableView toView:[_chatTabview superview]];
手势坐标
- (void)sigleTappedPickerView:(UIGestureRecognizer *)sender
{
//取得所点击的点的坐标
CGPoint point = [senderlocationInView:self];
// 判断该点在不在区域内
if (CGRectContainsPoint(CGRectMake(0,FIXED_PICKER_SELECTED_ORIGNALY, FIXED_PICKER_SELECTED_WIDTH, FIXED_PICKER_SELECTED_HEIGHT), point))
{
/ Do what you want
}
}
)
判断cell
- (void)pressAction:(UILongPressGestureRecognizer *)longPressGesture
{
NSInteger count;
if (longPressGesture.state == UIGestureRecognizerStateBegan) {//手势开始
NSLog(@"开始");
CGPoint point = [longPressGesture locationInView:_chatTabview];
NSIndexPath *currentIndexPath = [_chatTabview indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按
count = currentIndexPath.row;
NSLog(@"%ld",count);
}
if (longPressGesture.state == UIGestureRecognizerStateEnded) {//手势开始
}
}
1.手势冲突
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//和collectView
if([touch.view isDescendantOfView:_imgCollectView]){
return NO;
}
//和tableViewCell
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
return YES;
}