关于scrollview上加tableView滑动冲突

刚入职新公司,就看看新公司代码+熟悉环境,闲来无事自己瞎捣鼓捣鼓


不废话,切入正题

在scrollview上加一个tablevew,scrollview水平滑动,tableview支持滑动删除,此时两者滑动冲突


直接贴代码吧

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    UIView *view = touch.view;
    if ([view isKindOfClass:[UITableView class]] || [@"UITableViewCellContentView" isEqualToString:[[view class] description]] )
    {
        return NO;
    }
    
    return YES;
}


顺便提及一下:

在UIView上面加scrollView,scroll里面加customView (UIview),UIView上面加拖拽手势,使customView能够拖拽移动,解决scrollView和UIPanGestureRecognizer的冲突

viewController对应的view加手势UIPanGestureRecognizer

- (IBAction)touchDragGesture:(UIPanGestureRecognizer *)sender {
    CGPoint point = [sender locationInView:self.scrollView];
    if (sender.state == UIGestureRecognizerStateBegan) {
        for (UIView *subView in [self.scrollView subviews]) {
            if ([subView isKindOfClass:[customView class]]) {

                 //do something
            }
        }
    }else if (sender.state == UIGestureRecognizerStateEnded) {
            //do something
    }else{
            //do something
    }
}

在scrollview里面


-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *result = [super hitTest:point withEvent:event];
    
    NSArray *subViews = self.subviews;
    for (UIView *subView in subViews) {
        if ([subView isKindOfClass:[customView class]]) {
            customView *table = (customView *)subView;
            
            CGPoint buttonPoint = [table convertPoint:point fromView:self];
             if ([table pointInside:buttonPoint withEvent:event])
             {
                 
                 return [self superview];
             }    
        }
    }
    return result;
}

ok,完工!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值