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
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
