UIPanGestureRecognizer inside UIScrollView

I have the following problem with a UIPanGestureRecognizer inside a UIScrollView :

 UIScrollView *sv = [[UIScrollView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)]; sv.contentSize = CGSizeMake(200, 100 *100); for (int i = 0; i < 100; i++) { UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, 200, 100)]; UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panTile:)]; [panGesture setDelegate:self]; [panGesture setEnabled:FALSE]; [newView addGestureRecognizer:panGesture]; UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; [longPressRecognizer setDelegate:self]; [newView addGestureRecognizer:longPressRecognizer]; [sv addSubview:newView]; } 

The full scroll view is filled with small fragments, each of which implements a panorama gesture to make them draggable. The problem is that - by doing this - it prevents scrolling from scroll to scroll. Dragging and dropping tiles works fine instead. When I turn off tile tile gestures, scrolling works fine. Gesture gestures tiles somewhat hides the scroll view, own gesture. My idea was to disable tile tile gestures from the start. The gesture is activated as soon as the user makes a long press on the tiles. The problem is that the user needs to lift his finger and then touch the tile again to drag it. When the drag and drop is finished, I turn on the long press and turn off the pan gesture again. So longPress: looks like this:

 - (void)longPress:(UILongPressGestureRecognizer *) gestureRecognizer { for (UIGestureRecognizer *r in gestureRecognizer.view.gestureRecognizers) { if ([r isKindOfClass:[UIPanGestureRecognizer class]]) { [r setEnabled:TRUE]; } } //pan gesture should take over here... } 

Is it possible to glue a long press and pan gestures so that the user can not raise his finger? Or maybe another solution?

+4
source share

Source: https://habr.com/ru/post/1381527/


All Articles