Forward vertical scrolls from UIScrollView to a sibling UITableView

后端 未结 2 1963
北荒
北荒 2021-02-13 14:22

I have a view controller with this hierarchy:

View Controller:

  • UIScrollView (scrollable horizontally)
  • UITableView (scrollable vertically)
2条回答
  •  -上瘾入骨i
    2021-02-13 14:39

    If the tableview is contained within the scroll view I believe you can set up the scroll view's gesture recognizers to respond only if the table view's gesture recognizers fail. I haven't had a chance to try this, but you should be able to set up a dependency between the gestures for each of the views.

    UITableView* tableView = ...;
    UIScrollView* scrollView = ...;
    for (UIGestureRecognizer* r in scrollView.gestureRecognizers)
    {
        for (UIGestureRecognizer* tableRecognizer in tableView.gestureRecognizers)
        {
            [r requireGestureRecognizerToFail:tableRecognizer];
        }
    }
    

提交回复
热议问题