GestureRecognizers do not receive touch events while UIScrollView slows down

I have a horizontal scrollable UICollectionView filled with vertically scrollable UITableViews (both are subclasses of UISCrollView). When the scroll gesture starts to scroll in any direction, no other gesture recognizers are recognized until they slow down.

So, if I scroll horizontally from one table to the next, try scrolling the vertical orientation of the table before braking is completed, it will continue to scroll horizontally. This is very frustrating.

+4
source share
1 answer

, UIGestureRecognizerDelegate:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}

, UIScrollView MUST UIScrollView, UIScrollView ( UITableView UICollectionView) .

.

, , UIScrollViews , , .

, , .

UISwipeGestureRecognizer* verticalSwipe = [[UISwipeGestureRecognizer alloc] init];
verticalSwipe.direction = UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp;
verticalSwipe.delegate = self;
for (UIGestureRecognizer *gesture in self.collectionView.gestureRecognizers){
    [gesture requireGestureRecognizerToFail:verticalSwipe];
}
[self.collectionView addGestureRecognizer:verticalSwipe];

tableView, , , tableView, , .

    UISwipeGestureRecognizer* horizontalSwipe = [[UISwipeGestureRecognizer alloc] init];
    horizontalSwipe.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
    horizontalSwipe.delegate = self;
    for (UIGestureRecognizer *gesture in tableView.gestureRecognizers){
        [gesture requireGestureRecognizerToFail:horizontalSwipe];
    }
    [tableView addGestureRecognizer:horizontalSwipe];

:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}

, ViewView TableView .

+4

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


All Articles