UIScrollViews all scroll in the same time

给你一囗甜甜゛ 提交于 2019-12-10 10:44:50

问题


I have a screen with several scrollViews. How to achieve this: When i tap on one and swipe they all start to scroll. I of course know UIScrollViewDelegate methods and what i trying to do so far is combine -setContentOffset:animated: with scrollViewDidScroll and it works but only for one case - when i start scrolling with delegate scrollview.

How to dynamically change delegate? depends which scroll view user select?


回答1:


Keep an array of all of your UIScrollView objects. Make sure all of their delegates point to the same object (or if that's not possible, there is some sort of handler that gets called on scrollViewDidScroll). Then use setContentOffset to adjust the offsets. You had the right idea, but you just want to make sure all scroll views except the current view (which is determined by the delegate method argument) is scrolling.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  for (UIScrollView *view in self.scrollViews) {
    if (scrollView != view) {
      [view setContentOffset:scrollView.contentOffset];
    }
  }
}


来源:https://stackoverflow.com/questions/13152602/uiscrollviews-all-scroll-in-the-same-time

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