Setting contentOffset programmatically triggers scrollViewDidScroll(以编程方式设置 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.
我使用 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.
如何以编程方式修改我的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式设置 contentOffset 触发 scrollViewDidScrol
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01