Create two scrolling UIScrollView or transfer inertia between scroll views

In our application, you can create a question by searching for parameters from several third-party sources. Most of these search results are displayed as full-sized table cells, as their data matches this format (there is a bunch of metadata text that I can display next to the thumbnail).

However, in the case of images, the presentation of the collection makes more sense. But now I am faced with the problem of vertically scrolling a table containing a vertical view of the scroll collection.

http://www.screencast.com/t/7Z48zkkW

I can make it work somewhat by capturing viewDidScrollin the collection view and updating the parent scroll view instead of the corresponding offsets, but it only works well when the user actively drags the collection view.

self.collectionVC.scrollViewDidScroll = ^(UIScrollView *scrollView) {
    @strongify(self);
    if (self.tableView.contentOffset.y < self.scrollingHeightOffset && scrollView.contentOffset.y > 0) {
        CGFloat maxheight = MIN(self.scrollingHeightOffset, self.tableView.contentOffset.y + scrollView.contentOffset.y);
        self.tableView.contentOffset = CGPointMake(0, maxheight);
        scrollView.contentOffset = CGPointMake(0, 0);
    } else if (scrollView.contentOffset.y < 0 && self.tableView.contentOffset.y > -topGuide) {
        CGFloat minheight = MAX(-topGuide, self.tableView.contentOffset.y + scrollView.contentOffset.y);
        self.tableView.contentOffset = CGPointMake(0, minheight);
        scrollView.contentOffset = CGPointMake(0, 0);
    }
};

When “casting” a collection view, scrolling abruptly stops, losing the inertia of the collection view. Touching to view a table for scrolling has another problem, since I don't fix this when it reaches the end and scrolls through the collection view.

Right now, viewing a collection lives in a table cell, but if necessary, it can be a peer. I am trying to determine the best way to make these two scrollviews display as one.

+4
2

, . viewDidScroll , , , - .

scrollViews , . .

, . , , , .

0

, , .

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView1.panGestureRecognizer addTarget:self action:@selector(didRecognizePanGesture:)];
    [self.tableView2.panGestureRecognizer addTarget:self action:@selector(didRecognizePanGesture:)];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.selectedTableView == scrollView)
    {
        if (scrollView == self.tableView1)
        {
            self.tableView2.contentOffset = scrollView.contentOffset;
        }
        else if (scrollView == self.tableView2)
        {
            self.tableView1.contentOffset = scrollView.contentOffset;
        }
    }
}

- (void)didRecognizePanGesture:(UIPanGestureRecognizer*)gesture
{
    if (gesture.state == UIGestureRecognizerStateBegan)
    {
        if (self.selectedTableView != nil) //this is gonna make stop the previous scrollView
        {
            [self.selectedTableView setContentOffset:self.selectedTableView.contentOffset animated:NO];
        }
        self.selectedTableView = (UITableView*)gesture.view;
    }
}
0

All Articles