Vishal Mali
Vishal Mali

Reputation: 71

Perform synchronized scrolling with two scroll views

I have two scrollers in same view(like 2 vertical scrollers). I want to do something like, when i scroll one scroller the another scroll should also move by the same amount and in same direction as first one.

Is there any way i can achieve this??? Any sample will be really appreciated.

Thanks in Advance.

Vishal.

Upvotes: 4

Views: 3208

Answers (2)

luvieere
luvieere

Reputation: 37534

I think I've done this... I did it like this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
  if ([scrollView isEqual: theFirstScrollView])
  {
        theSecondScrollView.contentOffset =
              CGPointMake(theFirstScrollView.contentOffset.x, 0);
  }
  else
  {
        theFirstScrollView.contentOffset = 
              CGPointMake(theSecondScrollView.contentOffset.x, 0);
  }
}

The scrollviews must share the same delegate, and it handles the behavior in the scrollViewDidScroll method.

Upvotes: 6

coneybeare
coneybeare

Reputation: 33101

You will have to intercept the touches and manually send a scrollTo: message to both scrollviews.

Upvotes: 0

Related Questions