Reputation: 3274
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!
Upvotes: 2
Views: 2059
Reputation: 435
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.
Upvotes: 1
Reputation: 3095
Add this method to your buttons' UIPanGestureRecognizer's delegate:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return (otherGestureRecognizer == _scrollView.panGestureRecognizer);
}
Upvotes: 1
Reputation: 3509
Give a thought to UILongPressGestureRecognizer. This might help you: Combine longpress gesture and drag gesture together
Upvotes: 0