scrollViewDidEndScrollingAnimation 未被调用 [英] scrollViewDidEndScrollingAnimation not getting called

查看:44
本文介绍了scrollViewDidEndScrollingAnimation 未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 scrollview 完成滚动时执行一些操作,所以我在 scrollViewDidEndScrollingAnimation 委托方法中编写了该操作.当 rect 不可见并且 scrollview 滚动到新的 rect 时,它工作正常.但是当 rect 已经可见时,scrollViewDidEndScrollingAnimation 方法不会被调用,所以写在 scrollViewDidEndScrollingAnimation 中的方法不会被调用.但是我想调用该操作,有人知道如何在滚动视图完成滚动时调用该方法吗?

提前致谢!

解决方案

我认为这个方案能吸引一些人.实际发生的是 scrollViewDidEndScrollingAnimation 仅在您显式调用 setContentOffset:animated:scrollRectToVisible:animated: 方法时调用.>

作为 UIScrollViewDelegate 协议参考 状态:

<块引用>

讨论
滚动视图在其结束时调用此方法setContentOffset:animated: 和的实现scrollRectToVisible:animated: 方法,但前提是动画是请求.

那怎么办?好吧,我们不要忘记通常滚动视图中内容数据的偏移不是动画的.相反,它是不断更新 contentOffset 值的结果.因此,您可以使用 scrollViewDidScroll: 委托方法根据特定的 contentOffset 触发您的方法.

或者,如果在每个滚动手势之后都要做某事 - 特别是在私有 UIScrollViewPanGestureRecognizer 之后 - 那么你可以在 scrollViewDidEndDecelerating::

<块引用>

讨论
滚动视图在滚动时调用此方法运动停止.UIScrollView 的减速属性控制减速.

I want to perform some action when scrollview finish scrolling, so I wrote that acton in scrollViewDidEndScrollingAnimation delegate method. It is working fine when rect is not visible and scrollview scrolls to new rect. But when rect is already visible scrollViewDidEndScrollingAnimation method will not be called and so the method written inside scrollViewDidEndScrollingAnimation will not get called. But I want to call that action, can anyone knows how to call that method when scrollview finish scrolling?

Thanks in advance!

解决方案

I think this one catches a few people out. What actually happens is that scrollViewDidEndScrollingAnimation is only called if you explicitly invoke either the setContentOffset:animated: or the scrollRectToVisible:animated: methods.

As the UIScrollViewDelegate Protocol Reference states:

Discussion
The scroll view calls this method at the end of its implementations of the setContentOffset:animated: and scrollRectToVisible:animated: methods, but only if animations are requested.

So what to do? Well, let's not forget that typically the offsetting of content data in a scroll view is not animated. Rather, it is the result of continuously updating the contentOffset value. So, you could possibly trigger your method based upon a specific contentOffset using the scrollViewDidScroll: delegate method.

Alternatively, if it is something to be done after every scroll gesture - specifically, after the private UIScrollViewPanGestureRecognizer - then you could do it in scrollViewDidEndDecelerating::

Discussion
The scroll view calls this method when the scrolling movement comes to a halt. The decelerating property of UIScrollView controls deceleration.

这篇关于scrollViewDidEndScrollingAnimation 未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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