1

I have a long, horizontal, narrow UIScrollView containing several buttons side-by-side. When a user drags a button vertically, a specific method is triggered (via a UIPanGestureRecognizer), and the scrollview doesn't scroll (even if his/her drag begins to go left or right). This is all good.

When a user drags horizontally anywhere on the scrollview, including directly on a button, the UIPanGestureRecognizer ignores the effect and the scrollview should scroll. It's the last effect I'm having trouble with: when the user horizontally drags directly on a button, the scrollview doesn't scroll. How can I "pass through" that horizontal gesture to the scrollview?

Thanks for reading!

Stunner
  • 12,025
  • 12
  • 86
  • 145
Rogare
  • 3,234
  • 3
  • 27
  • 50

3 Answers3

1

Add this method to your buttons' UIPanGestureRecognizer's delegate:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return (otherGestureRecognizer == _scrollView.panGestureRecognizer);
}
hatfinch
  • 3,095
  • 24
  • 35
  • That's _exactly_ what I needed. Thanks! All of my angle-calculating functions are no longer necessary. I'll just disable scrolling at the start of the vertical-button-drag and enable afterwards. – Rogare Nov 14 '13 at 12:17
1

On UIScrollView you can override

- (BOOL)touchesShouldCancelInContentView:(UIView *)view

Subclass UIScrollView (or UITableView) and return YES. It will cancel any touch from subviews when scrolling starts.

Aurelien Cobb
  • 435
  • 4
  • 6
0

Give a thought to UILongPressGestureRecognizer. This might help you: Combine longpress gesture and drag gesture together

Community
  • 1
  • 1
instaable
  • 3,449
  • 2
  • 24
  • 31