Perform synchronized scrolling with two scroll views

白昼怎懂夜的黑 提交于 2019-12-10 16:23:55

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/1438661/perform-synchronized-scrolling-with-two-scroll-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!