手势和点击

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值