10
votes

i have horizontal UIScrollView which is extended from UIScrollView and i added UIButtons horizontally. i can only scroll out of the buttons area, but if i want to scroll over any buttons is fires UIControlEventTouchUpInside event. I don't want this. i want to fire UIControlEventTouchUpInside action if i click and i want to scroll if i scroll.

so how can i pass scroll event from UIButton to UIScrollView?

4
It would help if you created a simple code example to illustrate what you are doing, because in the simple case of adding a UIButton to a UIScrollView, you can drag the scroll view postion around even if you started the touch event on a button.Yetanotherjosh

4 Answers

4
votes

Subclass UIScrollView, return YES in the - touchesShouldCancelInContentView: method.

3
votes

that functionality is already built in. When you have a UIControl element as a subview of a scroll view and a touch event is detected, it is initially passed to the UIScrollView. IF, after a moment or two there hasn't been sufficient movement in the touch event, it gets passed on to the button.

0
votes

If you subclass NSButton and make your button of that type and override the following in your subclass you can pass the events back to the parent view, in your case the scroll view

The following would make the button never trigger an event and instead all would be dealt with by the parent view:

- (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
    [self.nextResponder touchesBegan:touches withEvent:event];      
}

- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
    [self.nextResponder touchesMoved:touches withEvent:event];  
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event 
{
    [self.nextResponder touchesEnded:touches withEvent:event];  
}

If you want to have the button deal with one of those events instead use

[super touchesEnded:touches withEvent:event];
0
votes

Try this:

self.button.exclusiveTouch = YES

Worked like a charm for me!