Gesture problem: UISwipeGestureRecognizer + UISlider

前端 未结 3 1489
温柔的废话
温柔的废话 2020-12-01 03:41

Got a gesture related problem. I implemented UISwipeGestureRecognizer to get swipe left and right events and that is working fine. However the problem I\'m facing is that th

3条回答
  •  心在旅途
    2020-12-01 04:18

    The simplest way to handle this is probably to prevent the gesture recognizer from seeing touches on your slider. You can do that by setting yourself as the delegate, and then implementing

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        if ([touch.view isKindOfClass:[UISlider class]]) {
            // prevent recognizing touches on the slider
            return NO;
        }
        return YES;
    }
    

    If this doesn't work, it's possible the slider actually has subviews that receive the touch, so you could walk up the superview chain, testing each view along the way.

提交回复
热议问题