设置contentOffset以编程方式触发scrollViewDidScroll [英] Setting contentOffset programmatically triggers scrollViewDidScroll

查看:489
本文介绍了设置contentOffset以编程方式触发scrollViewDidScroll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有几个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.

我使用UIScrollViewDelegatescrollViewDidScroll:跟踪运动.我查询已更改的UIScrollViewcontentOffset,然后通过将它们的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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