ios 8 - buttons in horizontal scroll view intercepting pan event - scroll does not work

后端 未结 5 1249
刺人心
刺人心 2020-11-28 06:28

I have a horizontal scroll view with a line of buttons. The scroll view will not scroll unless I do an extremely fast swipe.

If I set the buttons to userInteractionE

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 06:51

    I made a subclass of UIScrollView to fix this issue. You only need this method in it:

    - (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
    {
        UITouch *touch = [touches anyObject];
    
        if(touch.phase == UITouchPhaseMoved)
        {
            return NO;
        }
        else
        {
            return [super touchesShouldBegin:touches withEvent:event inContentView:view];
        }
    }
    

    Then just remember to set the class to your subclass in the storyboard if you're using one and you're good to go.

提交回复
热议问题