以编程方式设置 contentOffset 触发 scrollViewDidScrol

时间:2022-11-23
本文介绍了以编程方式设置 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.

如何以编程方式修改我的 contentOffsets 以不触发 scrollViewDidScroll:?

How can I modify my contentOffsets programmatically to not trigger scrollViewDidScroll:?

实施说明....每个 UIScrollView 都是自定义 UIView 的一部分,它使用委托模式回调处理协调各种 contentOffset 的呈现 UIViewController 子类 值.

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.

推荐答案

可以在不触发委托回调scrollViewDidScroll:的情况下改变UIScrollView的内容偏移量,通过设置 UIScrollView 的边界并将原点设置为所需的内容偏移量.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:使用 pagingEnabled 的 UIScrollView 中页面之间的照片应 下一篇:Swift - 如何从照片库中获取最后拍摄的 3 张照片

相关文章

最新文章