UIScrollView scrollRectToVisible:animated: 有没有一种方法可以在动画结束时调用方法
有没有办法知道动画何时结束并且 uiscrollview 何时停止。
Is there a way to know when the animation has end and uiscrollview has come to rest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,使用 scrollViewDidEndScrollingAnimation
Yup use scrollViewDidEndScrollingAnimation
我这样做是因为有时使用委托对我来说并不实际,就像我在 UIViewController 转换中这样做一样:
I do it like this because sometimes using the delegate isn't practical for me, like if i'm doing it in UIViewController transition:
实现 UIScrollViewDelegate 的委托方法UIScrollView 的方式如下:
当您通过调用
setContentOffset:animated:
或scrollRectToVisible:animated: 启动滚动时,使用
方法(带有动画:YES)。scrollViewDidEndScrollingAnimation:
来检测滚动动画何时结束:如果要监视由触摸手势启动的滚动视图运动,请使用
scrollViewDidEndDecelerating:
方法,该方法在滚动运动停止时调用。Implement UIScrollViewDelegate delegate methods for your UIScrollView the following way:
Use
scrollViewDidEndScrollingAnimation:
to detect when the scrolling animation concludes when you've initiated the scrolling by callingsetContentOffset:animated:
orscrollRectToVisible:animated:
methods (with animated:YES).If you want to monitor scroll view motion that's been initiated by touch gestures, use
scrollViewDidEndDecelerating:
method, which is called when the scrolling movement comes to a halt.您需要涵盖三种(!)情况。谢谢,苹果。
(小心不要忘记中间的额外的“if”子句。)
然后在
fingerOrProgrammaticMoveDone()
中,执行您需要的操作。一个很好的例子就是处理分页滚动的噩梦。很难知道你在哪一页。
You need to cover THREE (!) cases. Thanks, Apple.
(Be careful to not forget the extra "if" clause in the middle one.)
Then in
fingerOrProgrammaticMoveDone()
, do what you need.A good example of this is the nightmare of handling paged scrolling. It is very, very hared to know what page you are on.
scrollViewDidEndDecelerating:
当scrollView完全停止时调用UIScrollView委托方法。scrollViewDidEndDecelerating:
UIScrollView delegate method is called when scrollView stops completely.