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

后端 未结 5 1240
刺人心
刺人心 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条回答
  • 2020-11-28 06:34

    I've had this problem with a UITableView which has custom UITableViewCells with UIButtons on it. I put this in my UITableview class.

    - (BOOL)touchesShouldCancelInContentView:(UIView *)view {
        return YES;
    }
    

    Solved my problem.

    EDIT: Just to clearify, you can create a subclass of UIScrollview and add this to solve the problem.

    0 讨论(0)
  • 2020-11-28 06:34

    I have same issue and I solved it by creating a subclass of UIScrollView and set it's cancelContentTouches value to TRUE and its working fine.

    - (BOOL)touchesShouldCancelInContentView:(UIView *)view {
           return YES;
    }
    

    Hope it will work for you.

    0 讨论(0)
  • 2020-11-28 06:35

    I found that in iOS 8, the UIScrollView's underlying UIPanGestureRecognizer is not respecting the UIScrollView's delaysContentTouches property. I consider this an iOS 8 bug. Here's my workaround:

    theScrollView.panGestureRecognizer.delaysTouchesBegan = theScrollView.delaysContentTouches
    
    0 讨论(0)
  • 2020-11-28 06:49

    This hack works for me:

    UITapGestureRecognizer *nothingTap = [[UITapGestureRecognizer alloc] init];
    nothingTap.delaysTouchesBegan = YES;
    [_scrollView addGestureRecognizer:nothingTap];
    

    credit: https://devforums.apple.com/thread/241467

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题