UIScrollViews 同时滚动 [英] UIScrollViews all scroll in the same time

查看:20
本文介绍了UIScrollViews 同时滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个滚动视图的屏幕.如何实现这一点:当我点击一个并滑动时,它们都开始滚动.我当然知道 UIScrollViewDelegate 方法,到目前为止我尝试做的是将 -setContentOffset:animated:scrollViewDidScroll 结合起来,它只适用于一种情况 - 当我开始使用委托滚动视图滚动时.

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?

推荐答案

保留所有 UIScrollView 对象的数组.确保它们的所有委托都指向同一个对象(如果不可能,则在 scrollViewDidScroll 上调用某种处理程序).然后使用 setContentOffset 调整偏移量.您的想法是正确的,但您只想确保除当前视图(由委托方法参数确定)之外的所有滚动视图都在滚动.

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];
    }
  }
}

这篇关于UIScrollViews 同时滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆