关于手势冲突

在self.view 中加入 scrollview 或者 uitableview,
在 self.view 上加上 button ,touch 事件 不响应。

在网上找了方法,
设置

       _scrollView.delaysContentTouches = YES;
       _scrollView.canCancelContentTouches = NO;

依旧不能解决。
于是乎
把 button 改成 UIImageView,userInteractionEnabled = YES,加上 tap 手势即可

 _consultFloatView  = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"detail_consult"]];
        _consultFloatView.frame = CGRectMake(kScreenWidth - 200, kScreenHeight - 140, 48 * kPercentage, 48 * kPercentage);
_consultFloatView.userInteractionEnabled = YES;
       UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_consult:)];
        tap.cancelsTouchesInView = NO;
        [_consultFloatView addGestureRecognizer:tap];
          [self.view addSubview:self.consultFloatView];

    _consultFloatView.frame = CGRectMake(kScreenWidth - 100, kScreenHeight - 140, 48 * kPercentage, 48 * kPercentage);

在 ViewController 实现toushi 事件

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    DLog(@"触摸 触发");
    UITouch *touch = [touches anyObject];
    if ([touch.view isKindOfClass:[UIImageView class]] && [touch.view isEqual:_consultFloatView]) {
        CGPoint point = [touch locationInView:self.view];
        if (point.y < 64 || point.y > kScreenHeight - TABBAR_FOOTER_HEIGHT) {
            return;
        }
        _consultFloatView.center = point;
    }

}

猜你喜欢

转载自blog.csdn.net/yanyanforest/article/details/78141241