IOS UIScrollView will cancel setting UIButton to scroll

I have UIButtons in a UIScrollView, but I don't want to delay button clicks. However, as soon as the scroll view detects a drag / scroll, I want to cancel touching UIButton and continue scrolling UIScrollView.

I have included the following ...

_scrollView.delaysContentTouches = NO;

... but (obviously) pressing a button does not cancel when dragging. Does anyone have any suggestions as to how I can implement this functionality?

+5
source share
2 answers

You can override this method UIScrollView.

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

And in your UIButton you have to add another method for various control events.

  • show highlight effect for UIControlEventTouchDown.
  • UIControlEventTouchUpInside | UIControlEventTouchUpOutside;
  • UIControlEventTouchCancel.
+7

scrollViewWillBeginDragging, , . , , , , .

+1

All Articles