UIScrollView overrides my subview's pan gesture recognizers
12,011
Solution 1
Here's what works for me:
UIPanGestureRecognizer *subviewPanRecognizer = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(panSubview:)];
[subview addGestureRecognizer:subviewPanRecognizer];
// play nice with subview's pan gesture
[scrollView.panGestureRecognizer
requireGestureRecognizerToFail:subviewPanRecognizer];
Solution 2
Set canCancelContentTouches
property of UIScrollView
to false
if you don't want to scroll on touching subviews.
Comments
-
Mr Ordinary almost 2 years
If I have a scrollView with a subview and the subview has a pan gesture recognizer, the scrollView's pan gesture override's the subview's pan. What I want is the opposite, I think, so that is I drag a subview it will pan within the scroll view, yet if I touch another area the scroll view will pan as normal. Is there an easy way to set that up?
-
Norswap over 10 yearsThat seems to be the default behaviour (that's what I'm observing in practice in a UIScrollView with a UIImageView subview). Could someone confirm/infirm?
-
Anthony Mills almost 9 yearsWorks beautifully, especially when applying a delegate on the subview and implementing
gestureRecognizerShouldBegin:
.