Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView overrides my subview's pan gesture recognizers

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?

like image 286
Mr Ordinary Avatar asked Sep 23 '13 10:09

Mr Ordinary


2 Answers

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];
like image 65
Benjamin Cheah Avatar answered Sep 28 '22 15:09

Benjamin Cheah


Set canCancelContentTouches property of UIScrollView to false if you don't want to scroll on touching subviews.

Original answer

like image 30
ViruMax Avatar answered Sep 28 '22 17:09

ViruMax