Ios moves touch event between two uiscrollview

I am creating an iOS layout consisting of a UITableView and a UIScrollView . UIScrollView is located inside the cell of the UITableView table and can be scrolled both horizontally and vertically. The diagram below shows this situation. If the user starts scrolling up / down on a UIScrollView , the scrolling event should fire setContentOffset in the table view, and not setContentOffset to view the scroll, while the top of the scroll will be on the dashed line (this is a constant height). Then the scrolling touch event should fire setContentOffset to view the scroll, and not to represent the table.

Otherwise: when the user starts scrolling in the table view, he must call setContentOffset to represent the table until the scroll view reaches the dashed line. Then the scroll view should handle setContentOffset .

My problem is how to pass touch events between the table view and the scroll view during one sliding action.

enter image description here

+4
source share
2 answers

It sounds like one of those times when you need something completely specific and custom. Therefore, attempts to do something smart with gesture recognizers will not be enough.

The main problem is that methods for managing gesture recognizers, such as gestureRecognizer:shouldReceiveTouch: and gestureRecognizerShouldBegin: only affect the beginning of gestures (or new touches, not current ones), but you want one continuous gesture to switch between control of each species. Therefore, for this reason, I think you will need to place a large transparent view on the entire screen using the gesture recognizer on the hard disk, and in your handlePan method, select which view you want to configure, and then call setContentOffset directly in this view. You can use the translation of the pan recognizer and the existing content offset to calculate a new one. I know that this is not very elegant, but I cannot think of another way to achieve the desired effect.

+2
source

I'm not sure if this will work, but you can try to do something like this:

  • Option

    self.scrollView.panGestureRecognizer = self.tableView.panGestureRecognizer;

  • Option

    [self.scrollView addGestureRecognizer:self.tableView.panGestureRecognizer];

  • Option

     [self.tableView.panGestureRecognizer requireGestureRecognizerToFail:self.scrollView.panGestureRecognizer]; 
0
source

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


All Articles