如何测试滚动视图是否弹跳?
如何测试滚动视图是否弹跳?弹跳结束时有通知什么的吗?
How can I test if the scroll view is bouncing? Is there a notification or something when the bounce ends?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
以下是我检测滚动视图是否水平弹动的方法:
Here is how I detected if the scroll view is bouncing horizontally:
我已经实现了 UIScrollView 的扩展来处理垂直和水平滚动。即使 contentInsets 不为零,并且内容不够大,无法覆盖滚动视图插入,这也适用:
Objective-C
Swift 3.0+
For RxSwiftscrollViewDidScroll 映射到
isBouncing
并使用distinctUntilChanged
进行过滤即可。I've implemented extension for UIScrollView to handle this for vertical and horizontal scrolling. This will work even with non-zero contentInsets and in case when content is not big enough for covering scrollView insets:
Objective-C
Swift 3.0+
For RxSwift you can just map
scrollViewDidScroll
withisBouncing
and filter withdistinctUntilChanged
.对 Justin 方法的一个小修改,允许 contentInset:
A minor amendment to Justin's method, allowing for contentInset:
是的...查看 UIScrollViewDelegate 规范,实现包括以下两个方法在内的方法,并相应地设置 UIScrollView 的委托:
您可能对scrollViewDidEndDecelerating 最感兴趣。这些也适用于 UITableView,这是我最初找到它们的地方(UITableView 继承自 UIScrollView)。
Yes... check out the UIScrollViewDelegate spec, implement the methods including the two below, and set your UIScrollView's delegate accordingly:
You will probably be most interested in scrollViewDidEndDecelerating. These also work in UITableView which is where I originally found them (UITableView inherits from UIScrollView).
老问题,但我刚刚遇到了类似的问题,想补充一点,检查滚动视图内容是否大于滚动视图的框架是一个好主意:
现在这可以确保滚动视图足够大,可以位于滚动弹跳状态,因此如果滚动视图很小,它并不总是评估为 true。
干杯
Old question but I just ran into a similar issue and wanted to add that it is a good idea to also check that the scroll views content is larger than the scroll view's frame:
This now makes sure the scroll view is large enough to be in a scroll-bouncing state, so that if the scroll view is small it does NOT always evaluate to true.
Cheers
对于那些能够在滚动视图中向下“弹跳”以更新视图内容的人。 (并且该事件仅触发一次。)
For those of you who would be able to "bounce" downwards in a scrollview in order to update contents of the view. (And the event is only fired once.)
使用 Glavid 的答案,我也将弹跳添加到底部,并添加为一个类别
Using Glavid's answer, I added bouncing to bottom also, and added as a category