问题描述
我在页面上有几个UIScrollView
.您可以独立滚动它们,也可以将它们锁定在一起然后一起滚动.当它们被锁定时,会发生问题.
I've got a a few UIScrollView
on a page. You can scroll them independently or lock them together and scroll them as one. The problem occurs when they are locked.
我使用UIScrollViewDelegate
和scrollViewDidScroll:
跟踪运动.我查询已更改的UIScrollView
的contentOffset
,然后通过将它们的contentOffset
属性设置为匹配来将更改反映到其他滚动视图.
I use UIScrollViewDelegate
and scrollViewDidScroll:
to track movement. I query the contentOffset
of the UIScrollView
which changed and then reflect change to other scroll views by setting their contentOffset
property to match.
太好了....除了我注意到很多额外的电话.以编程方式更改滚动视图的contentOffset
会触发调用委托方法scrollViewDidScroll:
.我尝试使用setContentOffset:animated:
代替,但是我仍然在委托上得到触发器.
Great.... except I noticed a lot of extra calls. Programmatically changing the contentOffset
of my scroll views triggers the delegate method scrollViewDidScroll:
to be called. I've tried using setContentOffset:animated:
instead, but I'm still getting the trigger on the delegate.
如何以编程方式修改我的contentOffset而不触发scrollViewDidScroll:
?
How can I modify my contentOffsets programmatically to not trigger scrollViewDidScroll:
?
实施说明....每个UIScrollView
都是自定义UIView
的一部分,该自定义UIView
使用委托模式来回调呈现的UIViewController
子类,该子类负责协调各种contentOffset
值.
Implementation notes....Each UIScrollView
is part of a custom UIView
which uses delegate pattern to call back to the presenting UIViewController
subclass that handles coordinating the various contentOffset
values.
推荐答案
通过设置UIScrollView
的范围,可以更改UIScrollView
的内容偏移而无需触发委托回调scrollViewDidScroll:
.原点设置为所需的内容偏移量.
It is possible to change the content offset of a UIScrollView
without triggering the delegate callback scrollViewDidScroll:
, by setting the bounds of the UIScrollView
with the origin set to the desired content offset.
CGRect scrollBounds = scrollView.bounds;
scrollBounds.origin = desiredContentOffset;
scrollView.bounds = scrollBounds;
这篇关于设置contentOffset以编程方式触发scrollViewDidScroll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!