Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIScrollView cancel UIButton touch on scroll

I have some UIButtons within a UIScrollView, but I do not want to delay the button touches. However, as soon as the scroll view detects a drag/scroll, I want to cancel the UIButton touch and proceed with the scrolling of the UIScrollView.

I have included the following...

_scrollView.delaysContentTouches = NO;

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

like image 367
lucien Avatar asked Apr 04 '13 18:04

lucien


2 Answers

You can override this method of UIScrollView.

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

And in your UIButton, you should add different method for different control events.

  1. show highlight effect for UIControlEventTouchDown.
  2. trigger button for UIControlEventTouchUpInside | UIControlEventTouchUpOutside;
  3. clear highlight effect for UIControlEventTouchCancel.
like image 146
wods Avatar answered Sep 19 '22 23:09

wods


You could use scrollViewWillBeginDragging to fire off a notification and handle the button canceling by listening for it in your buttons' code. I think this is what you are trying to do, but I'm not sure if I have understood your question correctly.

like image 22
Psiticosis Avatar answered Sep 19 '22 23:09

Psiticosis